Skip to content

Instantly share code, notes, and snippets.

@ttsugriy
Created December 19, 2016 06:44
Show Gist options
  • Save ttsugriy/c23e83ccd7589a2120c150d5e43983e2 to your computer and use it in GitHub Desktop.
Save ttsugriy/c23e83ccd7589a2120c150d5e43983e2 to your computer and use it in GitHub Desktop.
int minMoves(vector<int>& nums) {
int base = numeric_limits<int>::max();
int sum = 0;
for (int i = 0; i < nums.size(); ++i) {
sum += nums[i];
base = min(base, nums[i]);
}
return sum - base * nums.size();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment