[閒聊] 每日leetcode

看板Marginalman作者 (QQ)時間2月前 (2024/02/26 11:24), 編輯推噓3(301)
留言4則, 4人參與, 2月前最新討論串2/228 (看更多)
100.same tree 題目給定兩個tree 判斷他們是不是長一樣 判斷節點一樣加遞迴左右子樹 class Solution: def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: if p is not None and q is not None: return p.val == q.val and self.isSameTree(p.left, q.left) and self.i sSameTree(p.right, q.right) elif p is None and q is None: return True else: return False ---- Sent from BePTT on my iPhone 13 mini -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.242.32.63 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708917849.A.8FC.html

02/26 11:31, 2月前 , 1F
大濕
02/26 11:31, 1F

02/26 11:31, 2月前 , 2F
大師
02/26 11:31, 2F

02/26 11:32, 2月前 , 3F
大師
02/26 11:32, 3F

02/26 11:48, 2月前 , 4F
大師
02/26 11:48, 4F
文章代碼(AID): #1bt0HPZy (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bt0HPZy (Marginalman)