首页 > 其他 > 详细

20-Valid Parentheses

时间:2019-08-16 20:52:28      阅读:92      评论:0      收藏:0      [点我收藏+]

题目:判断大、中、小括号是否合法。“()”、"([)]"、"{(([])}"

def isValid(string):
    dic = {‘}‘:‘{‘,‘]‘:‘[‘,‘)‘:‘(‘}
    stack = []
    for s in string:
        if s not in dic:
            stack.append(s)
        else:
            if len(stack)>0 and dic[s]==stack[-1]:
                stack.pop()
            else:
                return False

    return True

  

20-Valid Parentheses

原文:https://www.cnblogs.com/kingshine007/p/11366033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!