题解 | #有效括号序列#

有效括号序列

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

全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务