Re: [閒聊] 每日leetcode

作者: SecondRun (雨夜琴聲)   2024-04-14 16:47:04
※ 引述《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跳過==

Links booklink

Contact Us: admin [ a t ] ucptt.com