# Leetcode 462 - Minimum Moves to Equal Array Elements II

`Note:`

- Math knowledge: for
`[a, b]`

, find a num that has the shortest distance to both nums. It must be`between`

a and b. - Now we have
`len / 2`

pairs, ofc we need to`sort`

them first, then find the`median`

. - The median must be a num that is between every pair!
- When len is odd, it’s the middle num.
- When len is even, it’s the average of the 2 middle nums.

`Question:`

Given an integer array `nums`

of size `n`

, return the minimum number of moves required to make all array elements equal.

In one move, you can increment or decrement an element of the array by 1.

Test cases are designed so that the answer will fit in a `32-bit`

integer.

`Example:`

1 | Input: nums = [1,2,3] |

`Code:`

1 | /** |