[프로그래머스 / C++] 올바른 괄호

Taegang Yun·2023년 9월 6일
1

https://school.programmers.co.kr/learn/courses/30/lessons/12909

스택 활용할 줄 아냐? 의 기본 문제급이다

#include <string>
#include <iostream>
#include <stack>

using namespace std;

stack<int> st;

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

1트 성공!

profile
언젠간 전문가가 되겠지

0개의 댓글

관련 채용 정보