C++/programmers 코딩테스트(level 2) C++

[C/C++] programmers Level 2 짝지어 제거하기

CE : 하랑 2023. 10. 5. 09:05

 

 

 

 

 

코드

#include <string>
#include <stack> // 스택

using namespace std;

int solution(string s)
{
    int answer = 0;
    stack<char> st; // 스택 이용
    
    for(int i=0;i<s.size();i++){
        
        if(st.empty() || st.top()!=s[i]){
            st.push(s[i]);
        }else{
            st.pop();
        }
    }
    
    if(st.empty()){
        answer=1;
    }

    return answer;
}