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 // [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12973
class Solution import java.util.Stack;
{ class Solution{
public int solution(String s) public int solution(String s){
{ Stack<Character> stack = new Stack<>();
int idx = 0;
char[] stack = new char[s.length()];
for(char ss : s.toCharArray()){ for(char ss : s.toCharArray()){
if(idx > 0 && stack[idx-1] == ss){ if(!stack.empty() && stack.peek() == ss) stack.pop();
idx -= 1; else stack.push(ss);
} else{
stack[idx] = ss;
idx++;
}
} }
return (idx==0)?1:0; return (stack.empty())?1:0;
} }
} }