leetcode-easy-others-20 Valid Parentheses

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