精華區beta Marginalman 關於我們 聯絡資訊
※ 引述《sustainer123 (caster )》之銘言: : https://leetcode.com/problems/sum-of-left-leaves : 404. Sum of Left Leaves : 求左子葉和 C# code public class Solution { public int SumOfLeftLeaves(TreeNode root, bool isLeft = false) { if (root == null) return 0; if (isLeft && root.left == null && root.right == null) return root.val ; return SumOfLeftLeaves(root.left, true) + SumOfLeftLeaves(root.right, false); } } 窩只寫簡單 中級偶爾 HARD跳過== -- (づ′・ω・)づ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.158.160.52 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1713084427.A.1F8.html ※ 編輯: SecondRun (49.158.160.52 臺灣), 04/14/2024 16:52:14