【leetcode❤python】 20. Valid Parentheses
#-*- coding: UTF-8 -*-
#利用栈的思想
#如果输入的左测扩则入栈,如果输入为右侧扩,判断其是否与当前栈顶配对,如果匹配则删除这一对,否则return False
#'(', ')', '{', '}', '[' and ']'
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
left_tag=['(','{','[']
right_tag=[')','}',']']
stack_list=[]
match_dic={'(':')','{':'}','[':']'}
for i in range(len(s)):
curcheck=s[i]
if left_tag.__contains__(curcheck):
stack_list.append(curcheck)
elif right_tag.__contains__(curcheck):
if len(stack_list)!=0 and match_dic.get(stack_list[-1])==curcheck:
stack_list.pop()
else:
return False
else:return False
return True if len(stack_list)==0 else False
sol=Solution()
print sol.isValid('[')
【leetcode❤python】 20. Valid Parentheses的更多相关文章
- 【LeetCode练习题】Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...
- 【leetcode❤python】 125. Valid Palindrome
#-*- coding: UTF-8 -*- class Solution(object): def isPalindrome(self, s): ""&quo ...
- 【leetcode❤python】 36. Valid Sudoku
#-*- coding: UTF-8 -*-#特定的九个格内1-9的个数至多为1#依次检查每行,每列,每个子九宫格是否出现重复元素,如果出现返回false,否则返回true.class Solutio ...
- 【leetcode❤python】242. Valid Anagram
class Solution(object): def isAnagram(self, s, t): if sorted(list(s.lower()))==sorted(list ...
- LeetCode解题笔记 - 20. Valid Parentheses
这星期听别人说在做LeetCode,让他分享一题来看看.试了感觉挺有意思,可以培养自己的思路,还能方便的查看优秀的解决方案.准备自己也开始. 解决方案通常有多种多样,我觉得把自己的解决思路记录下来,阶 ...
- leetCode练题——20. Valid Parentheses
1.题目 20. Valid Parentheses——Easy Given a string containing just the characters '(', ')', '{', '}', ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- [Leetcode][Python]32: Longest Valid Parentheses
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 32: Longest Valid Parentheseshttps://oj ...
- 【LeetCode】20. Valid Parentheses 有效的括号
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:有效,括号,括号匹配,栈,题解,leetcode, 力扣 ...
随机推荐
- oracle ebs request一直pending
如果提交请求以后,状态一直是pending状态,可以在“工具”打开“Manager”,查看一下Maximum是否有设置错,另外pending的数量当前是多少. 如果Maximum是1,pending是 ...
- 夺命雷公狗jquery---4内容选择器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- html 复习
通过几次修改网页的经历,发现相关基础知识之薄弱,不得不再次花时间复习一遍.希望这是最后一次. 一 通用声明 HTML5 <!DOCTYPE html> HTML 4.01 <!DOC ...
- struts2 笔记04 杂记
流程: 1. StrutsPrepareAndExcuteFilter:StrutsPrepareAndExcuteFilter作为前端控制器,是整个Struts2的调度中心. 2. ActionMa ...
- python logging 替代print 输出内容到控制台和重定向到文件
转自:http://blog.csdn.net/z_johnny/article/details/50740528
- simpleBLEPeripheral.c 文件分析
这个配置或者说任务, 让这个蓝牙设备成为了一个简单的BLE外设. 这里定义了外设的广播数据, 以及最重要, char被改变之后的回调, 引出后来的coreHandler里面的, ack 以及写e2pr ...
- Mysql String Functions
SUBSTRING_INDEX(str,delim,count) 按标识符截取指定长度的字符串 mysql); -> 'www.mysql' mysql); -> 'mysql.com' ...
- java.security.NoSuchAlgorithmException: DES KeyGenerator not available
更改jre,点击项目build path-->configure build path-->libraries-->jre library system-->edit--> ...
- ectouch第十一讲 之 ECTouch 菜单里如何添加文章链接
1.首先在 ectouch 后台添加好文章分类和文章内容(具体添加方法很简单,这里就不再赘述),然后在菜单管理里添加导航如下(链接地址的获取方法参考步骤 2):2.文章分类列表 域名/mobile/i ...
- 通达OA 免狗迁移到公网 的另类解决办法
1,通达OA 发布到公网 ,要真正的 Anywhere2,正版通达OA,有加密狗在本地机器上 ,通达必须检测有狗才可以运行3,阿里云服务器 (你想往上插加密狗都没地方的说..汗)4,本地ISP 不提 ...