class Solution: def dt(self, s): L = [] index = 0 Balance = True openss = "([{" closess = ")]}" while index < len(s) and Balance: closes = s[index] if closes in "({[": L.append(s[index]) else: if len(L) == 0: Balance = False else: opens = L.pop() Balance = openss.index(opens) == closess.index(closes) index = index + 1 if len(L) == 0 and Balance: return True else: return False a=Solution() print(a.dt('[)]')); False
括号匹配(python)
最新推荐文章于 2022-03-17 08:50:13 发布