Skip to content

Commit a6255d8

Browse files
authored
[20251022] PGM / LV2 / 짝지어 제거 / 이인희
Implement solution to remove adjacent pairs from a string.
1 parent 8c578d1 commit a6255d8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(String s){
6+
Stack<Character> stack = new Stack<>();
7+
for(char c : s.toCharArray()){
8+
if(!stack.isEmpty() && stack.peek() == c){
9+
stack.pop();
10+
}else{
11+
stack.push(c);
12+
}
13+
}
14+
return stack.isEmpty() ? 1 : 0;
15+
}
16+
}
17+
```

0 commit comments

Comments
 (0)