Simple Java Solution


  • 0
    H

    The strategy is just to add up all the numbers except the min one, and minus the min one for length-1 times.

    public class Solution {
        public int minMoves(int[] nums) {
            int sum=0;int min=nums[0];
            for(int i:nums) {sum=sum+i;if(min>i) min=i;}
            sum=sum-nums.length*min;
            return sum;
            
        }
    }
    

Log in to reply
 

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