[프로그래머스/Java] 올바른괄호

괜찮아요?·2023년 4월 4일
0

programmers

목록 보기
15/23

링크

코딩테스트 연습 > 스택/큐 > 올바른 괄호

코드

class Solution {

    boolean solution(String s) {
        int openCount = 0;
        int closeCount = 0;

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {openCount++} 
            else if (s.charAt(i) == ')') {closeCount++;}
            
            if (openCount < closeCount) {return false;}
        }
        if (openCount == closeCount) {return true;}
        return false;
    }
}
profile
할 수 있어요

0개의 댓글