leetcode

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

1887.cpp (385B)


      1 class Solution {
      2   public:
      3     int reductionOperations(const vector<int> &nums) {
      4         static int count[50001];
      5         memset(count, 0x00, sizeof(count));
      6 
      7         int res = 0, cnt = 0;
      8         for (const int n : nums)
      9             count[n]++;
     10         for (int i = 50000; i >= 0; i--) {
     11             if (count[i]) res += cnt += count[i];
     12         }
     13         return res - cnt;
     14     }
     15 };