강의

멘토링

로드맵

Inflearn Community Q&A

sohi03218057's profile image
sohi03218057

asked

Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)

2. Remove parenthesis characters (stack)

코드 리뷰 부탁드립니다!

Written on

·

341

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코딩-테스트

Quiz

스택 데이터 구조의 기본 원리는 무엇일까요?

먼저 들어온 요소가 먼저 나간다

가장 나중에 들어온 요소가 먼저 나간다

무작위 순서로 요소가 나간다

가장 먼저 들어온 요소가 가장 나중에 나간다

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

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

sohi03218057's profile image
sohi03218057

asked

Ask a question