https://leetcode.cn/problems/least-number-of-unique-integers-after-k-removals/
# https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/discuss/686343/Python-oror-3-Line-oror-Shortest-Simplest # remove "elements which have least count"
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int: counter = collections.Counter(arr) # print(counter). 计数器是有序的 # Counter({3: 3, 1: 2, 4: 1, 2: 1}) # 按元素出现次数counter[x]对数组arr进行排序 s = sorted(arr,key = lambda x:(counter[x],x)) # print(s) return len(set(s[k:]))View Code
标签:oror,Integers,arr,Removals,int,after,least,counter From: https://www.cnblogs.com/zijidan/p/16871956.html