404. Sum of Left Leaves
来源:互联网 发布:mac dmg u盘 编辑:程序博客网 时间:2024/04/30 19:19
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.
明确左节点的定义:左节点没有子节点,
root.left!=null&&root.left.left==null&&root.left.right==null 判断这个节点是左节点
public class Solution { int count=0; public int sumOfLeftLeaves(TreeNode root) { order(root); return count; } public void order(TreeNode root){ if(root==null) return ; if(root.left!=null&&root.left.left==null&&root.left.right==null) count+=root.left.val; order(root.left); order(root.right); }}
0 0
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves*
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- Python笔记--dict
- 网狐框架分析七--完整游戏流程
- 1005
- MySQL 自增 最大值
- Juniper防火墙路由模式IPSEC vpn和策略模式IPSEC vpn配置
- 404. Sum of Left Leaves
- 贪吃蛇大作战你个混蛋-别小看了异步消息
- 10.5第四次总结
- 保留位置
- 递归实现二分查找(Python2.7)
- javaScript 之History
- 分而治之_最大子数组_1
- 面向对象程序设计上机练习九(对象指针)
- 网狐框架分析六--整体框架