leetcode20. Valid Parentheses
2017-11-05 00:31
417 查看
leetcode20. Valid Parentheses
思路:
做一个栈,遇到对称的符号则出栈,否则入栈,最后判断栈是否为空。
思路:
做一个栈,遇到对称的符号则出栈,否则入栈,最后判断栈是否为空。
class Solution { public: bool isValid(string s) { string stack(s); int top = -1; if(s.size()<=0) return true; for(int i=0;i<s.size();i++){ switch(s[i]){ case '(': case '{': case '[': stack[++top] = s[i]; break; case ')': if(top<0 || stack[top]!='(') return false; top--; break; case '}': if(top<0 || stack[top]!='{') return false; top--; break; case ']': if(top<0 || stack[top]!='[') return false; top--; break; default: return false; } } if(top==-1) return true; else return false; } };
相关文章推荐
- 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] 20. Valid Parentheses
- [LeetCode]20. Valid Parentheses
- leetcode(20). Valid Parentheses
- 【LeetCode】20 Valid Parentheses (c++实现)
- LeetCode - 20. Valid Parentheses
- 20.[Leetcode]Valid Parentheses
- LeetCode 20 -- Valid Parentheses
- LeetCode 20 Valid Parentheses
- [leetcode:python]20.Valid Parentheses
- 【一天一道LeetCode】#20. Valid Parentheses
- [LeetCode] 20. Valid Parentheses 合法括号
- 【leetcode c++】 20 Valid Parentheses
- [leetcode] 20. Valid Parentheses