[Algorithm] 26 week(7.11 ~ 7.17) 2/3

Dev_min·2022년 7월 12일
0

algorithm

목록 보기
82/157

프로그래머스 올바른 괄호

function solution(s){
    const result = [];
    const stringArr = s.split('');
    
    if(stringArr[0] === ')') return false;

    for(let key in stringArr){
        if(stringArr[key] === '('){
            result.push(stringArr[key])
        } else {
            result.pop()
        }
    }

    return result.length === 0;
}
profile
TIL record

0개의 댓글