-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpractice.py
33 lines (29 loc) · 947 Bytes
/
practice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution(object):
def findLeastNumOfUniqueInts(self, arr, k):
count_number={}
result=0
for count in arr:
if count not in count_number:
count_number[count]=1
else:
count_number[count]+=1
for key,value in count_number.items():
if k!=0:
if value==1:
arr.remove(key)
count_number.pop(key)
k-=1
copy_count_number=count_number.copy()
for key,value in copy_count_number.items():
if value>1 and k!=0:
arr.remove(key)
count_number[key]=count_number[key]-1
k-=1
if value==0 or value==1:
del count_number[key]
k-=1
print(count_number)
return len(count_number)
SOL=Solution()
a=SOL.findLeastNumOfUniqueInts([2,1,1,3,3,3],3)
print(a)