Advertisement
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, left = 0, right = nums.size()-1;
- while(left<right){
- ans += (nums[right]-nums[left]);
- left++, right--;
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement