본문 바로가기
Algorithm/문제풀이

[Codility] Nesting (Easy) by javascript - AVAILABLE LESSONS 7

by 썸머워즈 2022. 4. 20.
반응형

▷ 문제 : AVAILABLE LESSONS 7 - Nesting (Easy)

 

Nesting coding task - Learn to Code - Codility

Determine whether a given string of parentheses (single type) is properly nested.

app.codility.com

▷ 해결 날짜 : 2022.04.20
▷ 소요 시간 : 15분
▷ 풀이 과정 :

이 문제 역시 괄호의 짝을 맞추는건데,앞에서 풀었던 Brackets 문제와 비슷해서 좀 난이도가 쉬운 문제였다.

 

▷ 구현

function solution(S){
    const opened = [];
    for(let nest of S){
        if(nest == '(') opened.push(nest);
        else {
            if(opened.length) opened.pop();
            else return 0;
        }
    }
    return opened.length ? 0 : 1;
}


▷ 복기 :

열심히하자

반응형


댓글

TOP