Simple JavaScript Code


  • 1
    E
    var minMoves = function(nums) {
        var min = nums[0];
        var sum = min;
        var len = nums.length;
        for(let i = 1; i < len; i++){
            sum += nums[i];
            min = nums[i] < min? nums[i]: min;
        }
        return sum - len * min;
    };
    

Log in to reply
 

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