Coding Test - cpp/Stack, Queue
[프로그래머스 lv 2 ] - 짝지어 제거하기
에드윈H
2021. 7. 14. 11:10
https://programmers.co.kr/learn/courses/30/lessons/12973
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int solution(string s)
{
if(s.size() % 2 != 0)
return 0;
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;
}