euisblue
12973. 짝지어 제거하기

Level 2 짝지어 제거하기

시간 복잡도: O(n)

1#include <bits/stdc++.h> 2using namespace std; 3 4int solution(string s) 5{ 6 const int SIZE = s.size (); 7 stack<char> stk; 8 9 for(int i=0; i<SIZE; ++i) { 10 if(stk.empty()) stk.push(s[i]); 11 else { 12 char t = stk.top(); 13 if(s[i] == t) stk.pop(); 14 else stk.push(s[i]); 15 } 16 } 17 18 return stk.empty(); 19}

괄호 검사 (VPS) 알고리즘이랑 똑같아서 그대로 풀어봤다.