Easy O(n) 11 lines Java Solution


  • 0
    E
    public class Solution {
        public int minMoves(int[] nums) {
            int min=Integer.MAX_VALUE,res=0;
            for(int i=0;i<nums.length;i++){
                if(min>nums[i]){
                    min=nums[i];
                }
                res+=nums[i];
            }
            return res-min*nums.length;
        }
    }
    

Log in to reply
 

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