# Leetcode 1481. Least Number of Unique Integers after K Removals

## 2. Solution

• Version 1
```class Solution:
def findLeastNumOfUniqueInts(self, arr, k):
stat = {}
for num in arr:
stat[num] = stat.get(num, 0) + 1
result = sorted(stat.items(), key=lambda item: item[1])
while k > 0:
k = k - result[0][1]
if k >= 0:
result.pop(0)
return len(result)```
• Version 2
```class Solution:
def findLeastNumOfUniqueInts(self, arr, k):
stat = {}
for num in arr:
stat[num] = stat.get(num, 0) + 1
result = sorted(stat.items(), key=lambda item: item[1])
index = 0
while k > 0:
k = k - result[index][1]
if k >= 0:
index += 1
return len(result) - index```
• Version 3
```class Solution:
def findLeastNumOfUniqueInts(self, arr, k):
stat = {}
for num in arr:
stat[num] = stat.get(num, 0) + 1
result = sorted(arr, key=lambda num: (stat[num], num))
return len(set(result[k:]))```

## Reference

1. https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/

0 条评论

• ### CodeForces 732B Cormen — The Best Friend Of a Man

B. Cormen — The Best Friend Of a Man time limit per test 1 second memory lim...

• ### Codeforces 1291 Round #616 (Div. 2) C. Mind Control（超级详细）

You and your n−1 friends have found an array of integers a1,a2,…,an. You have de...

• ### CodeForces 639 A

Bear and Displayed Friends time limit per test2 seconds memory limit per tes...

• ### 【CodeForces 489A】SwapSort

In this problem your goal is to sort an array consisting of n integers in at mos...

• ### Codeforces 626G Raffles(贪心+线段树)

G. Raffles time limit per test：5 seconds memory limit per test：256 megabytes inp...

• ### LWC 69: 773. Sliding Puzzle

版权声明：本文为博主原创文章，未经博主允许不得转载。 https://blog.csdn.n...

• ### 【Codeforces 738D】Sea Battle（贪心）

http://codeforces.com/contest/738/problem/D

• ### Ignatius and the Princess IV hdu 1029

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Oth...

• ### C#版(打败99.28%的提交) - Leetcode 347. Top K Frequent Elements - 题解

在线提交: https://leetcode.com/problems/top-k-frequent-elements/