29. The minimum number of K
problem:
Input n integers, find the smallest number K. 4,5,1,6,2,7,3,8 e.g. eight digital inputs, the minimum number is four 1,2,3,4 ,.
solve:
thought:
This problem simple reason, to sort the array first, then to remove the first k number.
python code:
# -*- coding:utf-8 -*-
class Solution:
def GetLeastNumbers_Solution(self, tinput, k):
# write code here
n=len(tinput)
if(k>n):
return []
for i in range(n-1):
for j in range(n-i-1):
if tinput[j]>tinput[j+1]:
tinput[j],tinput[j+1]=tinput[j+1],tinput[j]
return tinput[0:k]