올바른 괄호

bgy·2022년 9월 6일
0

스택 직접 만들어서

#include<string>
#include <iostream>
#include<stack>
using namespace std;

bool solution(string s)
{
    bool answer = true;
    stack<char> st;
    for(auto e:s){
        if(e=='('){
            st.push('(');
        }
        else{
            if(st.empty()){
                return false;
            }
            st.pop();
        }
    }
    if(!st.empty()){
        return false;
    }

    return answer;
}

0개의 댓글