python | #括号序列#

括号序列

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

#
# 
# @param s string字符串 
# @return bool布尔型
#
class Solution:
    def isValid(self , s ):
        # write code here
        dic = {'(':')','{' :"}",'[':']'}
        first = []
        for ss in s:
            if ss in dic.keys():
                first.append(ss)
            if ss in dic.values():
                if len(first) == 0:
                    return False
                tem = first.pop()
                if ss == dic[tem]:
                    continue
                else:
                    return False
        return True if len(first)==0 else False
全部评论

相关推荐

06-27 15:29
门头沟学院 Java
点赞 评论 收藏
分享
评论
4
收藏
分享

创作者周榜

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