https://programmers.co.kr/learn/courses/30/lessons/12909
#include<string>
#include <iostream>
using namespace std;
bool solution(string s)
{
int l =0;
int r = 0;
for(int i=0;i<s.size();i++){
if(s[i] == '(')
l++;
else
r++;
if(l<r)
return false;
}
if(l != r)
return false;
return true;
}
#include<string>
#include <iostream>
using namespace std;
bool solution(string s)
{
int n = 0;
for (int i = 0; i < s.length(); i++) {
if (n < 0)
return false;
if (s[i] == '(')
n++;
else if (s[i] == ')')
n--;
}
return n == 0;
}