728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public int solution(String S) { // write your code in Java SE 8 Stack<Character> st = new Stack<>(); for(int i=0; i<S.length(); i++){ switch(S.charAt(i)){ case '(' : st.push('('); break; case ')' : if(st.isEmpty()) return 0; st.pop(); break; } } if(st.isEmpty()) return 1; else return 0; } | cs |
'알고리즘 풀이 > Codility' 카테고리의 다른 글
Codility - Dominator (Leader) (0) | 2019.12.13 |
---|---|
Codility - StoneWall (Stacks and Queues) (0) | 2019.12.13 |
Codility - Fish (Stacks and Queues) (0) | 2019.12.13 |
Codility - Brackets (Stacks and Queues) (0) | 2019.12.13 |
Codility - Triangle (Sorting) (0) | 2019.12.13 |