作者DJYOSHITAKA (franchouchouISBEST)
看板Marginalman
標題Re: [閒聊] 每日leetcode
時間Fri May 17 22:10:33 2024
1325. Delete Leaves With a Given Value
還行
再找一題來寫好ㄌ
def removeLeafNodes(self, root: Optional[TreeNode], target: int) ->
Optional[TreeNode]:
if root is None:
return None
root.left = self.removeLeafNodes(root.left, target)
root.right = self.removeLeafNodes(root.right, target)
if root.left is None and root.right is None and root.val==target:
return None
else:
return root
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1715955036.A.C8C.html
→ yam276: 別捲了 不然用Rust捲 05/17 22:10
→ OnishiSaori: 大師 05/17 22:11
→ JIWP: 你要用c寫 05/17 22:11
推 NTUtriangle: 大師 05/17 22:12
推 sustainer123: 大師 05/17 22:13
推 argorok: 大師 05/17 22:14
→ DJYOSHITAKA: 肥肥我不會rust:( C是觸手在用的 05/17 22:17