题解 | #有效括号序列#

有效括号序列

https://www.nowcoder.com/practice/37548e94a270412c8b9fb85643c8ccc2

class Solution:
    def isValid(self , sstr) -> bool:
        # write code here
        dic={'(':')','[':']','{':'}'}
        list1=[]
        for i in s:
            if i in '({[':
                list1.append(dic[i])
            elif len(list1)==0:
                return False
            elif list1[-1]==i:
                list1.pop()
        return len(list1)==0

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务