国产毛多水多高潮高清,久热这里只有精品视频6,国内精品久久久久久久久电影网,国产男同志CHINA69,精品999日本久久久影院,人人妻人人澡人人爽人人精品,亚洲中文无码永久免

「Leetcode刷题」「20」有效的括号-4238精准一肖

「Leetcode刷题」「20」有效的括号

2026-01-18 00:41:44投稿人:博義堂BET98(撫順)有限公司圍觀8463 評論

「Leetcode刷題」「20」有效的括號

"""找入棧條件,出棧條件,棧頂與下一個元素的關(guān)系	,棧長度來判斷"""# leetcode submit region begin(Prohibit modification and deletion)class Solution:    def isValid(self, s: str) ->bool:        stack = []        for char in s:            if self.is_left_kuohao(char):                stack.append(char)                continue            if self.is_right_kuohao(char):                if len(stack) == 0:                    return False                left_part = stack.pop()                if self.match_kuohao(left_part,char):                    continue                else:                    return False        return len(stack) == 0    def is_left_kuohao(self, char):        return char in "([{ "    def is_right_kuohao(self, char):        return char in ")]}"    def match_kuohao(self, left_part, right_part):        if left_part == "(" and right_part == ")":            return True        if left_part == "[" and right_part == "]":            return True        if left_part == "{ " and right_part == "}":            return True        return False# leetcode submit region end(Prohibit modification and deletion)


-----------------------------------------------

如果是第一次閱讀文章 ,可以看看下面的話。

以上內(nèi)容由平時積累而成 ,盡量保證代碼與注釋合在一起,并未做過多篇幅的解釋 。不一定是最優(yōu)解