Easy to understand JS solution


  • 0
    K
    var minMoves = function(nums) {
        var min = nums[0];
        nums.forEach(function(num){
            if(min > num) min = num;
        })
        var total = nums.reduce(function(sum, num){
            return sum + num;
        });
        return total - min * nums.length;
    };
    
    

Log in to reply
 

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