[프로그래머스] 코딩테스트 연습 - 연습문제 Level 2 올바른 괄호

uoahy·2021년 9월 28일
0

Solution.java

class Solution {
    boolean solution(String s) {
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            count += (s.charAt(i) == '(') ? 1 : -1;
            if (count < 0) break;
        }

        return count == 0;
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

0개의 댓글