leetcode_num20_Valid Parentheses
2015-03-04 16:57
204 查看
Given a string containing just the characters
determine if the input string is valid.
The brackets must close in the correct order,
all valid but
not.
'(',
')',
'{',
'}',
'['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 Stack:#定义栈 后进先出 data=[] def push(self,item): self.data.append(item) def pop(self): if self.data == []: return False else: return self.data.pop() def length(self): return len(self.data) def clear(self): self.data=[] class Solution: # @return a boolean def isValid(self, s): p={'(':')','[':']','{':'}'} stack=Stack() stack.clear() for c in s: if c in p.keys(): stack.push(c) elif c in p.values(): k=stack.pop() if k==False or p[k]!=c: return False else: return False if stack.length() == 0: return True else: return False
相关文章推荐
- LeetCode Valid Parentheses
- [LeetCode] Valid Parentheses
- [LeetCode]Longest Valid Parentheses
- LeetCode Longest Valid Parentheses
- LeetCode---(32)Longest Valid Parentheses
- LeetCode力扣之Valid Parentheses
- LeetCode(20)Valid Parentheses
- leetcode--Valid Parentheses
- leetcode笔记:Valid Parentheses
- LeetCode 笔记系列八 Longest Valid Parentheses [lich你又想多了]
- leetcode解题报告20. Valid Parentheses
- leetcode 20|22|32. Valid Parentheses 22. Generate Parentheses 32. Longest Valid Parentheses
- LeetCode-Valid Parentheses
- Leetcode 20. Valid Parentheses
- LeetCode 32 Longest Valid Parentheses(最长合法的括号组合)
- Leetcode: Longest Valid Parentheses
- [leetcode刷题系列]Valid Parentheses
- leetcode---Valid Parentheses
- LeetCode Valid Parentheses
- [Leetcode] Valid Parentheses