Re: [閒聊] 每日leetcode已回收
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/05/17 22:10)推噓3(3推 0噓 4→)留言7則, 7人參與討論串237/1554 (看更多)
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
→
05/17 22:10,
1年前
, 1F
05/17 22:10, 1F
→
05/17 22:11,
1年前
, 2F
05/17 22:11, 2F
→
05/17 22:11,
1年前
, 3F
05/17 22:11, 3F
推
05/17 22:12,
1年前
, 4F
05/17 22:12, 4F
推
05/17 22:13,
1年前
, 5F
05/17 22:13, 5F
推
05/17 22:14,
1年前
, 6F
05/17 22:14, 6F
→
05/17 22:17,
1年前
, 7F
05/17 22:17, 7F
討論串 (同標題文章)
完整討論串 (本文為第 237 之 1554 篇):