Skip to content

Instantly share code, notes, and snippets.

@ttsugriy
Created December 19, 2016 05:16
Show Gist options
  • Save ttsugriy/712f7dfa90f1268299779bf02f9b8a12 to your computer and use it in GitHub Desktop.
Save ttsugriy/712f7dfa90f1268299779bf02f9b8a12 to your computer and use it in GitHub Desktop.
Minimum moves to equal array.
int minMoves(const vector& nums) {
int base = *min_element(nums.cbegin(), nums.cend());
return accumulate(nums.cbegin(), nums.cend(), 0) - base * nums.size();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment