乱人伦 国语对白海角社区,五月激情丁香婷婷综合中文字幕,欧美伊人婷婷久久五月综合,亚洲精品无amm毛片,亚洲男人第一无码AV网站,国产日韩欧美丝袜一区二区,亚洲一区精品在线观看

「Leetcode刷题」「20」有效的括号-奇异果体育APP下载手机版

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

2026-01-16 04:50:35投稿人:摩鑫娛樂注冊(棗莊)有限公司圍觀463 評論

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

"""找入棧條件,出棧條件,棧頂與下一個元素的關系,棧長度來判斷"""# 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)


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

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