Skip to content

Commit 055b0d9

Browse files
authored
Merge pull request #1255 from AlgorithmWithGod/LiiNi-coder
[20251028] PGM / LV2 / 괄호 회전하기 / 이인희
2 parents 963cdbd + ac318e5 commit 055b0d9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(String s) {
5+
char[] cs = s.toCharArray();
6+
int answer = 0;
7+
Deque<Character> q = new ArrayDeque<Character>();
8+
for(int i = 0; i<s.length(); i++){
9+
q = new ArrayDeque<Character>();
10+
for(int d = 0; d<s.length(); d++){
11+
12+
int id = (i+d) % s.length();
13+
char now = cs[id];
14+
Character pre = q.peekLast();
15+
if(pre == null){
16+
q.offer(now);
17+
}
18+
else if(pre == '(' && now == ')'){
19+
q.pollLast();
20+
}else if(pre == '{' && now == '}'){
21+
q.pollLast();
22+
}else if(pre == '[' && now == ']'){
23+
q.pollLast();
24+
}else{
25+
q.offer(now);
26+
}
27+
}
28+
if(q.size() ==0)answer++;
29+
}
30+
31+
return answer;
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)