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)


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