-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2592.cpp
More file actions
33 lines (29 loc) · 673 Bytes
/
Copy path2592.cpp
File metadata and controls
33 lines (29 loc) · 673 Bytes
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
const auto _ = []() {
ios_base::sync_with_stdio(0);
cout.tie(NULL);
cin.tie(NULL);
return NULL;
}();
// O(nlogn)
class Solution {
public:
int maximizeGreatness(vector<int> &nums) const {
sort(rbegin(nums), rend(nums));
int res = 0;
for (int i = 0; i < size(nums); i++) {
if (nums[i] < nums[res]) res++;
}
return res;
}
};
// O(n)
class Solution {
public:
int maximizeGreatness(const vector<int> &nums) const {
unordered_map<int, int> count;
int res = 0;
for (const int n : nums)
res = max(res, ++count[n]);
return size(nums) - res;
}
};