java one loop 5 line solution beats 99%


  • 4
    S
    public int minMoves(int[] nums) {
        int total = 0, min = nums[0];
        for (int n  : nums) {
            total += n;
            if (n < min) min = n;
        }
        return total - nums.length * min;
    }

Log in to reply
 

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