Problem Solving/Programmers
[Level 2] 짝지어 제거하기
kmkunk
2022. 3. 31. 16:32
import java.util.*;
class Solution {
public int solution(String s) {
Stack<Character> stack = new Stack<>();
for(int i=0; i<s.length(); i++) {
if(!stack.isEmpty() && stack.peek()==s.charAt(i)) {
stack.pop();
continue;
}
stack.push(s.charAt(i));
}
return stack.isEmpty() ? 1 : 0;
}
}