class Solution {
public:
int minMoves(vector<int>& nums) {
int n = nums.size();
if(n <= 1)
return 0;
int mn = nums[0]; //mn为最小数字
int sum = nums[0];
for(int i = 1; i < n; ++i)
{
mn = min(mn,nums[i]);
sum += nums[i];
}
return sum - mn*n;
}
};
Minimum Moves to Equal Array Elements
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.