슈콩

[프로그래머스] Lv.2 짝지어서 제거하기 본문

Algorithms/Programmers

[프로그래머스] Lv.2 짝지어서 제거하기

shukong 2025. 10. 13. 23:27

 

[문제]

https://school.programmers.co.kr/learn/courses/30/lessons/12973

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

[소스 코드]

import java.util.*;
class Solution
{
    public int solution(String s)
    {
        Stack<Character> stack = new Stack<>();
        for(Character c : s.toCharArray()){
            if(stack.isEmpty()) stack.push(c);
            else{
                if(stack.peek()==c) stack.pop();
                else stack.push(c);
            }
        }
        if(!stack.isEmpty()) return 0;
        return 1;
    }
}