[프로그래머스] 올바른 괄호 - (Stack) c++

ha·2022년 1월 10일
0

프로그래머스

목록 보기
4/21

Stack 풀이

bool solution(string s)
{
    bool answer = true;
    stack <char> st;
    for(int i=0;i<s.size();i++){
        if(s[i]=='('){
            st.push(s[i]);
        }
        else{
            if(!st.empty() && st.top()=='('){
                st.pop();
            }
            else{
                st.push(s[i]);
            }
        }
    }
    if(st.empty()) return true;
    else return false;
}

if(!st.empty() && st.top()=='(')

0개의 댓글