leetcode-easy-others-20 Valid Parentheses

时间:2019-06-11 21:59:21   收藏:0   阅读:97

mycode   95.76%

class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        dic = {):(, }:{, ]:[}
        res = []
        for i in s:
            if i in dic.keys():
                if res == [] or dic[i] != res[-1]:
                    return False
                res.pop()
            else:
                res.append(i)
        return res == []

 

原文:https://www.cnblogs.com/rosyYY/p/11006295.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!