Counseling ape - removing the array is greater than the number of number k

Title: Given an array and a k, the number of the array is greater than a number k deleted, the same number of other

dic = {}
res = []
for num in nums:
    if num not in dic:
        dic[num] = 1
    else:
        dic[num] +=1

for num in nums:
    if dic[num]<=m:
        res.append(num)
res = [str(i) for i in res]
print(' '.join(res))

  Note:

This is the first programming problem, which belongs to simple questions. First, a dictionary count the number of each number, and then traverse the original array, the number will be less than in the pre-k to save the list.

Guess you like

Origin www.cnblogs.com/kingshine007/p/11408012.html