首页 > 代码库 > LeetCode "Minimum Moves to Equal Array Elements"

LeetCode "Minimum Moves to Equal Array Elements"

Increasing all elements by 1 except one element, equals to decreasing that one element.

class Solution {public:    int minMoves(vector<int>& nums)     {        int minv = *min_element(nums.begin(), nums.end());                int ret = 0;        for(auto v : nums) ret += v - minv;                return ret;    }};

LeetCode "Minimum Moves to Equal Array Elements"