Advertisement
nikunjsoni

462

May 19th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int minMoves2(vector<int>& nums) {
  4.         sort(nums.begin(), nums.end());
  5.         int ans = 0, left = 0, right = nums.size()-1;
  6.         while(left<right){
  7.             ans += (nums[right]-nums[left]);
  8.             left++, right--;
  9.         }
  10.         return ans;
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement