-Code
import java.util.*;
class Solution {
public int solution(String s) {
int answer = 0;
int len = s.length();
Deque<String> deq = new ArrayDeque<>();
for (int i = 0; i < len; i++) {
for (String ss : s.split("")) {
if (!deq.isEmpty()) {
if (deq.peekLast().equals(validation(ss))) {
deq.pollLast();
continue;
}
}
deq.add(ss);
}
if (deq.isEmpty()) answer++;
deq.clear();
s = s.substring(1) + s.charAt(0);
}
return answer;
}
public static String validation(String s) {
if (s.equals(")")) return "(";
if (s.equals("}")) return "{";
if (s.equals("]")) return "[";
return null;
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 대충 만든 자판 (0) | 2025.03.07 |
---|---|
[프로그래머스/Java] 로또의 최고 순위와 최저 순위 (0) | 2025.03.01 |
[프로그래머스/Java] N개의 최소공배수 (0) | 2025.03.01 |
[프로그래머스/Java] 영어 끝말잇기 (0) | 2025.02.28 |
[프로그래머스/Java] 짝지어 제거하기 (0) | 2025.02.28 |