2 line C++ Solution


  • 0
    int minMoves2(vector<int>& nums) {
        nth_element(nums.begin(), nums.begin() + nums.size() / 2, nums.end());
        return accumulate(nums.begin(), nums.end(), 0, [&](int x, int y) {return x + abs(y - nums[nums.size() / 2]);});
    }

Log in to reply
 

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