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

dev-log·2021년 12월 6일
0
#include<string>
#include <iostream>
#include <stack>
using namespace std;

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

    return answer;
}
profile
배운 걸 기록하는 곳입니다.

0개의 댓글