Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (caster )時間1年前 (2024/04/14 16:15), 編輯推噓0(003)
留言3則, 3人參與, 1年前最新討論串116/1548 (看更多)
https://leetcode.com/problems/sum-of-left-leaves 404. Sum of Left Leaves 求左子葉和 Python Code: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def sumOfLeftLeaves(self, root: Optional[TreeNode]) -> int: result = 0 def dfs(node): nonlocal result if not node: return if node.left and not node.left.left and not node.left.right: result += node.left.val dfs(node.left) dfs(node.right) dfs(root) return result 寫得好醜 等等看一下解答 然後昨天hard還沒寫 哇哇嗚嗚嗚 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.65.164 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1713082540.A.CE0.html

04/14 16:15, 1年前 , 1F
大師
04/14 16:15, 1F

04/14 16:16, 1年前 , 2F
我是ez守門員
04/14 16:16, 2F

04/14 16:18, 1年前 , 3F
大師
04/14 16:18, 3F
文章代碼(AID): #1c6v2ipW (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c6v2ipW (Marginalman)