updated at 2022. 12. 20. 오후 11:54:05

This commit is contained in:
rl544
2022-12-20 23:54:05 +09:00
parent 332beefcd1
commit d5ef891101
@@ -1,19 +1,13 @@
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12973
class Solution
{
public int solution(String s)
{
int idx = 0;
char[] stack = new char[s.length()];
import java.util.Stack;
class Solution{
public int solution(String s){
Stack<Character> stack = new Stack<>();
for(char ss : s.toCharArray()){
if(idx > 0 && stack[idx-1] == ss){
idx -= 1;
} else{
stack[idx] = ss;
idx++;
if(!stack.empty() && stack.peek() == ss) stack.pop();
else stack.push(ss);
}
}
return (idx==0)?1:0;
return (stack.empty())?1:0;
}
}