Given an integer array nums of size n, return the minimum number of moves to make all array elements equal, where a move is incrementing n-1 elements by 1.

Input: [1,2,3] → Output: 3Input: [1,1,1] → Output: 0

Incrementing n-1 elements by 1 is equivalent to decrementing 1 element by 1. So the answer is sum(nums) - n*min(nums).

class Solution { public int minMoves(int[] nums) { int min = Integer.MAX_VALUE, sum = 0; for (int n : nums) { sum += n; min = Math.min(min, n); } return sum - min * nums.length; } }