leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1636.cpp (452B)


      1 class Solution {
      2   public:
      3     vector<int> frequencySort(vector<int> &nums) const {
      4         static int count[201];
      5 
      6         memset(count, 0x00, sizeof(count));
      7         for (const int n : nums)
      8             count[n + 100]++;
      9 
     10         sort(begin(nums), end(nums), [&](int a, int b) {
     11             const int x = count[a + 100];
     12             const int y = count[b + 100];
     13 
     14             return x != y ? x < y : a > b;
     15         });
     16 
     17         return nums;
     18     }
     19 };