알고리즘 풀이/프로그래머스
[프로그래머스][JAVA] 짝 지어 제거하기 (스택)
배게
2022. 3. 17. 22:11
728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import java.util.*; class Solution { public int solution(String s) { Stack<Integer> st = new Stack<>(); for(int i=0; i<s.length(); i++){ int curr = s.charAt(i); if(!st.isEmpty() && st.peek()==curr){ st.pop(); } else st.push(curr); } return (st.isEmpty())? 1:0; } } | cs |