Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int minMoves2(vector<int>& nums) {
- sort(nums.begin(), nums.end());
- int ans = 0;
- int start = 0, end = nums.size()-1;
- while(start < end) {
- ans += nums[end--] - nums[start++];
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment