LeetCode #1887

Reduction Operations to Make the Array Elements Equal

1개의 풀이 · C++

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
class Solution {
public:
    int reductionOperations(vector<int>& nums) {
        vector<int> V(50001);
        for(int x: nums)++V[x];
        int cnt = 0, ans = 0;
        for(int i = 1; i <= 50000; ++i) {
            if(V[i]) ans += cnt++ * V[i];
        }
        return ans;
    }
};

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.