leetcode-20-字符串题-有效的括号 发表于 2020-03-15 | 分类于 数据结构与算法 题目 解法1234567891011121314151617181920212223242526272829class Solution {public: bool isValid(string s) { if(s.empty()) return true; stack<char> help; for(auto x : s){ if(x == '(' || x == '[' || x == '{'){ help.push(x); }else{ if(!help.empty()){ if(x == ')' && help.top() == '('){ help.pop(); }else if(x == ']' && help.top() == '['){ help.pop(); }else if(x == '}' && help.top() == '{'){ help.pop(); }else{ return false; } }else{ return false; } } } return help.empty() ? true : false; }};