[Algorithm] 7 week(2.21 ~ 27) 1/3

Dev_min·2022년 2월 21일
0

algorithm

목록 보기
19/157

1732. Find the Highest Altitude

var largestAltitude = function(gain) {
    const roadPoint = [];
    roadPoint[0] = 0;
    [0, ...gain].forEach((num, index) => {
        roadPoint[index] = (roadPoint?.[index - 1] ?? 0) + num;
    }); 

    return roadPoint.sort((a, b) => (b - a))[0];    
};
profile
TIL record

0개의 댓글