LeetCode 20. 有效的括号
作者:互联网
栈
class Solution {
public:
bool isValid(string s) {
stack<char>stk;
for(auto c:s){
if(c=='(' || c=='{' || c=='[')stk.push(c);
else{
if(stk.size() && abs(stk.top()-c)<=2)stk.pop(); //ASCII码
else return false;
}
}
return stk.empty();
}
};
//栈
标签:20,string,isValid,public,top,stk,括号,LeetCode 来源: https://blog.csdn.net/m0_61794291/article/details/122633771