leetcode:Valid Parentheses
2015-02-19 13:37
162 查看
括号匹配
Given a string containing just the characters
The brackets must close in the correct order,
Given a string containing just the characters
'(',
')',
'{',
'}',
'['and
']', determine if the input string is valid.
The brackets must close in the correct order,
"()"and
"()[]{}"are all valid but
"(]"and
"([)]"are not.
class Solution { public: bool isValid(string s) { //use stack stack<char> st; for(int i = 0;i<s.size();i++) if(s[i] == ')' || s[i] == ']' || s[i] == '}') { if(st.empty()) return false; else { char c = st.top(); st.pop(); if ((c == '(' && s[i] != ')') || (c == '[' && s[i] != ']') || (c == '{' && s[i] != '}')) return false; } } else st.push(s[i]); return st.empty(); } };
相关文章推荐
- leetcode Longest Valid Parentheses
- [Leetcode] 32. Longest Valid Parentheses
- Leetcode题解 - 20. Valid Parentheses
- leetcode :Valid Parentheses
- LeetCode之20---Valid Parentheses
- leetcode-20-Valid Parentheses
- leetcode Valid Parentheses
- LeetCode(49)-Valid Parentheses
- 【一天一道LeetCode】#20. Valid Parentheses
- [LeetCode] 32. Longest Valid Parentheses
- [LeetCode] Longest Valid Parentheses
- LeetCode 20. Valid Parentheses
- 【Leetcode】Valid Parentheses
- LeetCode Longest Valid Parentheses
- leetcode习题解答:32. Longest Valid Parentheses
- leetcode(20. Valid Parentheses)
- [LeetCode]Valid Parentheses
- [Leetcode] 32. Longest Valid Parentheses
- Leetcode-32. Longest Valid Parentheses
- leetcode -- Valid Parentheses