Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 395 Bytes

64.md

File metadata and controls

16 lines (12 loc) · 395 Bytes

Minimum Moves to Equal an Array

LeetCode Link

    int minMoves2(vector<int>& nums) {

       sort(nums.begin(), nums.end());
    
       int median = nums[nums.size() / 2];
    
       int moves = 0;
       for (int num : nums) {
           moves += abs(num - median);
        }
    
       return moves;
    }