C++ solution using <algorithms>


  • 0
    A
        int minMoves(vector<int>& nums) {
            int x = *min_element(nums.begin(), nums.end());
            transform(nums.begin(), nums.end(), nums.begin(), [&x](int ni){return ni - x;});
            return accumulate(nums.begin(), nums.end(), 0);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.