20. Valid Parentheses
2016-07-26 19:35
393 查看
20. Valid Parentheses
Leetcode link for this questionDiscription:
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.
Analyze:
Code 1 :
class Solution(object): def isValid(self, s): """ :type s: str :rtype: bool """ li=[] left=['(','{','['] for i in s: if i in left: li.append(i) elif not li: return False elif i ==')' : if li[-1]!='(': return False else: li.pop() elif i =='}' : if li[-1]!='{': return False else: li.pop() elif i ==']' : if li[-1]!='[': return False else: li.pop() if li: return False else: return True
Submission Result:
Status: AcceptedRuntime: 44 ms
Ranking: beats 72.46%
相关文章推荐
- DDR Layout Guide-DDR内存布线指导
- hdu_5761_Rower Bo(xjb猜公式)
- 大数小数的加法
- 【Window编程】Step.1 我的第一个Windows程序
- 14. Longest Common Prefix
- 命令的查看帮助 和 命令行的历史
- Material Design的其他使用
- 13. Roman to Integer
- UVALive - 2701 Find The Multiple
- 阅一道简单程序,了解多线程编程;
- drop table中cascade的含义及用法
- 7. Reverse Integer
- Dynamics CRM 2016 修改服务器名字
- [SCU4437] Carries [2015 Sichuan Province Contest Final B]
- 6. ZigZag Conversion
- Linux-(C)多线程学习(入门)
- 弹性ListView
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- 1. Two Sum
- Android SyncAdapter同步实践