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
全部评论

相关推荐

shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
4 收藏 评论
分享
牛客网
牛客企业服务