[閒聊] 每日leetcode
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
討論串 (同標題文章)