435. Minimum Moves to Equal Array Elements
Sample code
1 | int min = nums[0]; |
One good explanation in discuss area:
sum + move*(n-1) = x*n
x = min + move
x = min + move
may be a liitle confusing, it comes from two observations:
- The minimum number will always be minium until it reaches the goal number, because other numbers(except the max) increased too.
- So if the final number is
x
, thenx = min + move