[Algorithm] 30 week(8.15 ~ 8.21) 3/3

Dev_min·2022년 8월 17일
0

algorithm

목록 보기
98/157

942. DI String Match

var diStringMatch = function(s) {
    let max = s.length;
    let min = 0;
    const result = [];

    s.split('').forEach((str) => {
        if(str === 'I'){
            result.push(min);
            min++;
        }
        if(str === 'D'){
            result.push(max);
            max--;
        }
    });
    
    result.push(max);
    return result;
};
profile
TIL record

0개의 댓글