Skip to content

Commit 110d898

Browse files
authored
Create 1636. Sort Array by Increasing Frequency
1 parent ba1a4fd commit 110d898

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
vector<int> frequencySort(vector<int>& nums) {
4+
unordered_map<int, int> map;
5+
for (auto i : nums) {
6+
map[i]++;
7+
}
8+
sort(nums.begin(), nums.end(), [&map](int a, int b) {
9+
if (map[a] == map[b]) {
10+
return a > b;
11+
}
12+
return map[a] < map[b];
13+
});
14+
return nums;
15+
}
16+
};

0 commit comments

Comments
 (0)