Re: [閒聊] 每日leetcode

看板Marginalman作者 (franchouchouISBEST)時間1年前 (2024/10/20 22:20), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串1014/1554 (看更多)
直接看別人寫的 這種題目我真的爛到懶得響 希望我這樣抄答案能記起來== def parseBoolExpr(self, expression: str) -> bool: stk = [] for c in expression: if c in ["(", ","]: continue elif c in ["t","f", "|", "&", "!"]: stk.append(c) elif c == ")": isTrue = False isFalse = False while stk[-1] in ["t", "f"]: c = stk.pop() if c == "t": isTrue = True else: isFalse = True operator = stk.pop() if operator == "|": stk.append("t" if isTrue else "f") elif operator == "&": stk.append("f" if isFalse else "t") elif operator == "!": stk.append("t" if isFalse else "f") return True if stk[0]=="t" else False -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1729434052.A.73E.html

10/20 22:24, 1年前 , 1F
別倦了
10/20 22:24, 1F
文章代碼(AID): #1d5H74S- (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1d5H74S- (Marginalman)