题解 | 合法括号序列判断
合法括号序列判断
https://www.nowcoder.com/practice/d8acfa0619814b2d98f12c071aef20d4
#include <vector>
class Parenthesis {
public:
bool chkParenthesis(string A, int n) {
// write code here
vector<char> stk;
for (auto c : A) {
if (c == '(') {
stk.push_back(c);
continue;
}
if(c ==')')
{
if(stk.empty()) return false;
stk.pop_back();
}
}
return stk.empty();
}
};
阿里云成长空间 763人发布
查看1道真题和解析