[Algorithm] 18 week(5.16 ~ 5.22) 3/3

Dev_min·2022년 5월 22일
0

algorithm

목록 보기
61/157

1827. Minimum Operations to Make the Array Increasing

var minOperations = function(nums) {
    let result = 0;
    let operation = 0;
    
    if(nums.length < 2) return 0;
    
    for(let i = 1; i < nums.length; i++){
        if(nums[i] <= nums[i-1]){
            operation = nums[i-1]-nums[i]+1
            result += operation
            nums[i] += operation
        }
    }
    return result;
};
profile
TIL record

0개의 댓글