인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

sohi0321's profile image
sohi0321

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

2. Remove parenthesis characters (stack)

코드 리뷰 부탁드립니다!

Written on

·

304

0

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.

 

function solution(str) {
    let answer = [];

    for(let i of str) {
        if(i != ')') answer.push(i);
    
        else {
            while(answer[answer.length - 1] != '(') {
                answer.pop();
            }
            answer.pop();
        }
    }
    return answer.join('');
}

let str = "(A(BC)D)EF(G(H)(IJ)K)LM(N)";
console.log(solution(str));

해당 코드도 괜찮은 코드인가요?

javascript코딩-테스트

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

네. 모든 입력의 답이 잘 나오는 잘 하신 코드입니다.

sohi0321's profile image
sohi0321

asked

Ask a question