当前位置:网站首页>Buddha's foot before examination: the third bullet of leetcode

Buddha's foot before examination: the third bullet of leetcode

2022-06-24 02:22:00 403 Forbidden

subject :

answer :

    def isValid(s):
        s = list(s)

        sym_dict = {")": "(", "}": "{", "]":"["}

        stack =[]
        close = []
        
        if len(s)%2 == 0:
            for i in range(len(s)):
                if s[i] in sym_dict.values():
                    stack.append(s[i])
                if s[i] in sym_dict.keys() and stack != [] and stack[-1] == sym_dict[s[i]]:
                    close.append(stack.pop())
            if stack == [] and len(close) == len(s)/2:
                return True
        return False   
原网站

版权声明
本文为[403 Forbidden]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211101204236742u.html

随机推荐