[Programmers] 스택/큐 - 올바른 괄호 (JavaScript)

eunji lee·2022년 9월 23일
0

알고리즘

목록 보기
10/11
function solution(s){
    let stack = [], count = 0 
    for(let x of s){
        if(x==='('){
            stack.push(x)
            count++;
        }
        else if (stack.length===0){
            return false 
        }
        else{
            stack.pop()
            count--;
            }
        }
    return count===0
    }
  • 스택 이용
profile
안녕하세요! 이은지 입니다.

0개의 댓글