20. Valid Parentheses
来源:互联网 发布:千里走单骑知乎 编辑:程序博客网 时间:2024/05/20 01:09
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.
概述:括号匹配,出门右转与C码解题方法
class Solution(object): def isValid(self, s): left = ['(','[','{'] right = [')',']','}'] match = {')':'(',']':'[','}':'{'} result = [] count = len(s) for i in xrange(count): if s[i] in left: result.append(s[i]) if s[i] in right: if len(result)!=0 and match[s[i]]==result[-1]: result.pop() else: return False if len(result) == 0: return True else: return False
阅读全文
0 0
- LeetCode 20. Valid Parentheses
- [LeetCode] 20.Valid Parentheses
- LeetCode --- 20. Valid Parentheses
- LeetCode 20.Valid Parentheses
- [Leetcode] 20. Valid Parentheses
- 20.Valid Parentheses
- 20.Valid Parentheses
- 20. Valid Parentheses
- 【leetcode】20. Valid Parentheses
- [leetcode] 20.Valid Parentheses
- [leetcode] 20. Valid Parentheses
- 20. Valid Parentheses
- 20. Valid Parentheses
- 20. Valid Parentheses
- Leetcode 20. Valid Parentheses
- 20. Valid Parentheses LeetCode
- 20. Valid Parentheses
- 20. Valid Parentheses
- Java交换排序
- 金币(NOIP2015)
- POJ 2411 Mondriaan's Dream
- Windows下Maven私服怎么搭建
- window启动过程
- 20. Valid Parentheses
- iOS开发学习笔记——UIWindow
- SELINUX
- 关于数据结构课程里不同节点定义对程序实现的影响
- Docker和宿主机之间共享文件
- 业务架构改进一
- [BZOJ4008][HNOI2015]亚瑟王 期望DP
- JavaScript对象继承
- 2222