404. Sum of Left Leaves

网友投稿 817 2022-10-09

404. Sum of Left Leaves

404. Sum of Left Leaves

Find the sum of all left leaves in a given binary tree.

Example:

3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution public int sumOfLeftLeaves(TreeNode root) { if (root == null) return 0; if (root.left != null && root.left.right == null && root.left.left == null) { return root.left.val + sumOfLeftLeaves(root.right); } return

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Rexdb-tester- 数据持久层框架性能测试程序
下一篇:semile:一个程序剖析框架,目前只支持C++
相关文章

 发表评论

暂时没有评论,来抢沙发吧~