๋ฌธ์
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ
์ง์ง์ด ์ ๊ฑฐํ๊ธฐ๋, ์ํ๋ฒณ ์๋ฌธ์๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด์ ๊ฐ์ง๊ณ ์์ํฉ๋๋ค. ๋จผ์ ๋ฌธ์์ด์์ ๊ฐ์ ์ํ๋ฒณ์ด 2๊ฐ ๋ถ์ด ์๋ ์ง์ ์ฐพ์ต๋๋ค. ๊ทธ๋ค์, ๊ทธ ๋์ ์ ๊ฑฐํ ๋ค, ์๋ค๋ก ๋ฌธ์์ด์ ์ด์ด ๋ถ
programmers.co.kr
์ฝ๋
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int solution(string s)
{
int answer = -1;
stack<char>st;
for(int i=0; i<s.length(); i++){
if(!st.empty()){
if(st.top()==s[i]) st.pop();
else st.push(s[i]);
}
else st.push(s[i]);
}
if(st.empty()) answer=1;
else answer=0;
return answer;
}
๋๊ธ