博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode 20 Valid Parentheses
阅读量:4221 次
发布时间:2019-05-26

本文共 1238 字,大约阅读时间需要 4 分钟。

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.

Subscribe to see which companies asked this question

python

class Solution(object):    def inValid(self,s):        num=[]        for i in range(len(s)):            if s[i]=="(" or s[i]=="{" or s[i]=="[":                num.append(s[i])            else:                if len(num):                    temp=num[-1]                    if s[i]==")":                        if temp=="(":                            num.pop()                        else:                            return False                    if s[i]=="}":                        if temp=="{":                            num.pop()                        else:                            return False                    if s[i]=="]":                        if temp=="[":                            num.pop()                        else:                            return False                else:                    return False        if not len(num):            return True        else:            return FalseC=Solution()s="("print C.inValid(s)

转载地址:http://zwqmi.baihongyu.com/

你可能感兴趣的文章
thinkphp源码没问题却各种报错,Namespace declaration statement has to be the very first statement in the script
查看>>
android:dkplayer中ijkplayer延迟长的问题,达到秒开的结果
查看>>
安卓:okhttp请求,获取返回数据
查看>>
安卓:股票筛选及分析系统
查看>>
Effective Java 学习笔记一 Object的方法
查看>>
使用 ctypes 进行 Python 和 C 的混合编程
查看>>
用scikit-learn学习DBSCAN聚类
查看>>
机器学习:Python实现聚类算法(三)之总结
查看>>
使用sklearn做单机特征工程
查看>>
Python 多线程技巧 用threading.Event代替time.sleep()
查看>>
工具】Cmake与gcc的关系
查看>>
struct中长度为0的数组用途与原理
查看>>
svm笔记
查看>>
C++ 继承&多态
查看>>
C++多继承的观察和7点体会(都是实用派的观点) good
查看>>
python socket编程详细介绍
查看>>
高人对libsvm的经典总结(全面至极)
查看>>
Linux下c语言多线程编程
查看>>
火狐下easyui1.3.*弹出window框定位不到中间解决把办法
查看>>
Hadoop启动报错NoClassDefFoundError: javax/activation/DataSource解决方案
查看>>