# Easy-题目47：20. Valid Parentheses

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
"""
stack=[]
for c in s:
if c in ['(','[','{']:
stack.append(c)
else:
if(len(stack)==0):
return False
top=stack[len(stack)-1]
if ((c == ')' and top=='(') or (c == ']' and top=='[') or (c == '}' and top == '{')):
stack.pop()
else:
return False

return len(stack)==0

43ms,beats 55.57%,众数40ms,27.91%

• 本文已收录于以下专栏：

## LeetCode OJ 20 Valid Parentheses [Easy]

LeetCode OJ 20 Valid Parentheses 题目描述： Given a string containing just thecharacters '(', ')', '{', ...

## Leet Code OJ 20. Valid Parentheses [Difficulty: Easy]

Valid Parentheses [Difficulty: Easy]： Given a string containing just the characters , determine if ...

## Leetcode笔记整理—easy篇—Valid Parentheses

**Valid Parentheses**问题简介：Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ...

## leetcode20:Valid Parentheses

Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and']',...
• GODBAR
• 2016年12月22日 21:58
• 174

## LeetCode 20. Valid Parentheses 辅助数据结构栈

Valid Parentheses 题意 注意 思路 代码 结果20. Valid Parentheses Given a string containing just the character...

## LeetCode20. Valid Parentheses

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the inpu...

## 20. Valid Parentheses （括号匹配）

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the in...

## LeetCode 20 Valid Parentheses (C,C++,Java,Python)

Problem: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', deter...

## [leetcode]20. Valid Parentheses(java)

举报原因： 您举报文章：Easy-题目47：20. Valid Parentheses 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)