Skip to content

Conversation

@LiiNi-coder
Copy link
Contributor

@LiiNi-coder LiiNi-coder commented Oct 22, 2025

Implement solution to remove adjacent pairs from a string.

🧷 문제 링크

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

🧭 풀이 시간

35 분

👀 체감 난이도

✏️ 문제 설명

  • 문자열이 주어지고, 이 문자열에서 연속 같은짝이있으면 계속 지워나가서 마지막에 빈문자열이 되는지 판단

🔍 풀이 방법

  • N^2방법 -> 스택

⏳ 회고

  • 처음엔 아래와 같이 N^2방식으로 풀다가 스택인것을 떠올려서 다시 푼문제
import java.util.*;
class Solution
{
    public int solution(String s)
    {
        int answer = -1;
        boolean[] isPasses = new boolean[s.length()];
        int i = 0;
        char[] cs = s.toCharArray();
        outer:while(i < s.length() - 1){
            //System.out.println("--outer시작");
            if(isPasses[i]){
                i++;
                continue;
            }
            char c = cs[i];
            int ni = i+1;
            while(true){
                if(ni >= s.length())
                    break outer;
                if(!isPasses[ni])
                    break;
                ni++;
            }
            char nc = cs[ni];
            //System.out.println("(i, ni) : " + i + ", " + ni);
            if(c == nc){
                //System.out.println("겹침");
                isPasses[i] = true;
                isPasses[ni] = true;
                i = 0;
            }else{
                i++;
            }
        }
        //System.out.println(Arrays.toString(isPasses));
        for(int ii = 0; ii<s.length(); ii++){
            if(!isPasses[ii])
                return 0;
        }
        return 1;
    }
}

Implement solution to remove adjacent pairs from a string.
@LiiNi-coder LiiNi-coder added the fail 😢 해설을 보고 풀었거나, 못 풀었을 때 label Oct 22, 2025
@ShinHeeEul ShinHeeEul merged commit a1edcd6 into main Oct 22, 2025
1 check passed
@LiiNi-coder LiiNi-coder added hint 💡 반례를 참고했거나 힌트를 얻고 풀었을 때 and removed fail 😢 해설을 보고 풀었거나, 못 풀었을 때 labels Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hint 💡 반례를 참고했거나 힌트를 얻고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants