Very simple Java solution


  • 0
    B

    public class Solution {
    public int minMoves(int[] nums) {
    if (nums.length <= 1) {
    return 0;
    }
    Arrays.sort(nums);
    int sum = 0;
    for (int i = 1; i < nums.length; i++) {
    sum += nums[i] - nums[0];
    }

        return sum;
    }
    

    }


Log in to reply
 

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