JAVA - 5 LINES - DON'T INCREMENT by N-1, DECREMENT BY 1!! Beats 97%


  • 0
    J
    class Solution {
        public int minMoves(int[] nums) {
            int lowest = nums[0];
            for(int num : nums) if(num < lowest) lowest = num;
            
            int count = 0;
            for(int num : nums) if(num > lowest) count += num - lowest;
            return count;
        }
    }
    

Log in to reply
 

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