Java O(N) solution.


  • 0
    J
    public class Solution {
        public int minMoves(int[] nums) {
            int sum = 0, min = Integer.MAX_VALUE;
            for(int num : nums) {
                sum+= num;
                min = Math.min(min, num);
            }
            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.