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)