Skip to main content

괄호문자제거

문제#

입력된 문자열에서 소괄호 ( ) 사이에 존재하는 모든 문자를 제거하고 남은 문자만 출력하는 프로그램을 작성하세요.

로직#

function solution(s){      var answer;    var stack=[];    for(var x of s){        if(x===')'){            while(stack.pop()!=='(');        }        else stack.push(x);    }    answer=stack.join('');    return answer;}
var str="(A(BC)D)EF(G(H)(IJ)K)LM(N)";console.log(solution(str));