leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1481.cpp (506B)
0 class Solution {
1 public:
2 int findLeastNumOfUniqueInts(const vector<int> &arr, int k) const {
3 unordered_map<int, int> um;
4 for (const int n : arr)
5 um[n]++;
7 static int count[100001];
8 size_t sz = 0;
9 for (const auto [_, cnt] : um)
10 count[sz++] = cnt;
12 sort(begin(count), begin(count) + sz);
13 for (int i = 0; i < sz; i++) {
14 k -= count[i];
15 if (k < 0) return sz - i;
16 }
18 return 0;
19 }
20 };