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