Clean C++ solution


  • 0
    int minMoves2(vector<int>& nums) {
            int median = nums.size()/2, res = 0;
            nth_element(nums.begin(), nums.begin()+median, nums.end());
            for(int num : nums)
                res += abs(num - nums[median]);
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.