Java version, easily


  • 0
    C
     public int minMoves(int[] nums) {
            if (nums.length <= 1) return 0;
            int min = Integer.MAX_VALUE;
            for(int i : nums){
                min = Math.min(i, min);
            }
            int sum = 0;
            for (int i = 0; i < nums.length; i++) {
                sum += nums[i]-min;
            }
    
            return sum;
        }
    

    Acutally, I did this in coursera interview...


Log in to reply
 

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