// 正しい括弧列か? bool is_right_parenthesis(string s){ ll L = s.size(); ll a=0; for(char c : s){ if(c=='(') a++; } ll b=L-a; if(a!=b) return false; ll cur=0; for(char c : s){ if(c=='('){ cur++; }else{ cur--; } if(cur<0) return false; } return true; }
verified
- "C. Yuhao and a Parenthesis"