[Algorithm] 41 week(11.07 ~ 11.13) 3/3

Dev_min·2022년 11월 9일
0

algorithm

목록 보기
134/157

739. Daily Temperatures

var dailyTemperatures = function(temperatures) {
    const answer = Array(temperatures.length).fill(0);
    
    const stack = [];
    for(let i = 0; i < temperatures.length; i++){
        while(stack.length && temperatures[i] > temperatures[stack[stack.length - 1]]){
            let last = stack.pop();
            answer[last] = i - last
        }
        stack.push(i)
    }

    return answer
};
profile
TIL record

0개의 댓글