My clean solution .Java O(n)


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

Log in to reply
 

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