Valid Parentheses @Leetcode -- Python
2014-05-08 16:16
309 查看
http://oj.leetcode.com/problems/valid-parentheses/
class Solution: # @return a boolean def isValid(self, s): if s == '': return True left = '([{' right = ')]}' stack = [] for i in s: if i == '(' or i == '[' or i == '{': stack.append(i) continue for j in xrange(3): if i == right[j]: if not stack or stack[-1] != left[j]: return False else: stack.pop() continue return not stack # test s = Solution() print s.isValid('()')
相关文章推荐
- LeetCode 20 — Valid Parentheses(C++ Java Python)
- 【Leetcode】【python】Longest Valid Parentheses
- leetcode 020 Valid Parentheses(Python)
- python写算法题:leetcode: 20. Valid Parentheses
- Python学习——leetcode(Valid Parentheses)
- Longest Valid Parentheses @Leetcode -- Python
- [Leetcode]32. Longest Valid Parentheses @python
- Leetcode Day5 20. Valid Parentheses Python 栈的实现
- [leetcode]Valid Parentheses @ Python
- LeetCode 32 Longest Valid Parentheses (C,C++,Java,Python)
- leetcode Longest Valid Parentheses python
- leetcode 日经贴,python code -Longest Valid Parentheses
- [leetcode:python]20.Valid Parentheses
- [LeetCode]题解(python):032-Longest Valid Parentheses
- LeetCode 20 Valid Parentheses (C,C++,Java,Python)
- [leetcode] Longest Valid Parentheses @python
- 【LeetCode with Python】 Valid Parentheses
- [LeetCode]题解(python):020-Valid Parentheses
- 【Leetcode】【python】Valid Parentheses
- leetcode 日经贴,python code -Valid Parentheses