LeetCode 20. Valid Parentheses
2017-12-19 11:03
429 查看
class Solution { public: bool isValid(string s) { stack<char> stack; for(int i=0;i<s.size();i++){ if(s[i]=='{'||s[i]=='['||s[i]=='(') stack.push(s[i]); else{ if(stack.size()==0) return false; char c=stack.top(); stack.pop(); char match; if(s[i]=='}') match='{'; else if(s[i]==')') match='('; else{ assert(s[i]==']'); match='['; } if(c!=match) return false; } } if(stack.size()!=0) return false; return true; } };
相关文章推荐
- Leetcode 20 Valid Parentheses
- 【LeetCode】20. Valid Parentheses
- leetcode 20. Valid Parentheses
- Leetcode 20. Valid Parentheses
- [LeetCode] 20. Valid Parentheses
- leetcode 20 Valid Parentheses 括号匹配
- leetcode-20-Valid Parentheses
- 【LeetCode】C# 20、Valid Parentheses
- LeetCode 20. Valid Parentheses
- leetcode 20. Valid Parentheses
- LeetCode | 20. Valid Parentheses
- [LeetCode] [C++] 20. Valid Parentheses
- LeetCode_Easy心得:20. Valid Parentheses(C语言)
- Leetcode 20 Valid Parentheses
- leetcode 20 Valid Parentheses
- [leetcode 20] Valid Parentheses
- LeetCode 20 - Valid Parentheses
- leetcode 20. Valid Parentheses
- leetcode[20]Valid Parentheses
- 20. Valid Parentheses-leetcode-java