Valid Parentheses
来源:互联网 发布:中科院力学研究所知乎 编辑:程序博客网 时间:2024/06/03 03:50
题目:
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(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
map = {'(':')', '{':'}', '[':']'}
res = []
for i in s:
if i=='(' or i=='{' or i=='[':
res.append(i)
elif len(res)!=0 and i==map[res[-1]]:
res.pop()
else:
return False
return len(res)==0
0 0
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- Valid Parentheses
- cstring和相关类型的相互转换int,double,char*
- 页面加载时弹出alert对话框
- Spring注解详解
- Fragment使用带参数的构造函数遇到的问题
- hkaAnimation->hkaAnimationBinding
- Valid Parentheses
- 经常访问的技术网站
- 原生JS操作DOM的一些常用方法集合【转】
- 机器学习之白话与实战adaboost元算法
- android 组件Spinner组件实例
- input验证是否为有效手机号码-js
- 欢迎使用CSDN-markdown编辑器
- 排序算法(二)冒泡排序
- POJ 3281