[JAVA] Reverse think (decrement one element) / T : O(N), S : O(1)


  • 0
    J
    class Solution {
        public int minMoves(int[] nums) {
            int min = Integer.MAX_VALUE;
            for(int num : nums){
                if(min > num){
                    min = num;
                }
            }
            
            int sum = 0;
            for(int num : nums){
                sum += (num - min);
            }
            return sum;
        }
    }
    

Log in to reply
 

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