LeetCode 404:Sum of Left Leaves
来源:互联网 发布:怎么开一个淘宝店铺 编辑:程序博客网 时间:2024/06/05 06:05
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 { int sum = 0; public int sumOfLeftLeaves(TreeNode root) { if(root == null) return 0; backTrack(root,root.left); backTrack(root,root.right); return sum; } public void backTrack(TreeNode parent,TreeNode root) { if(root != null) { backTrack(root,root.left); backTrack(root,root.right); if(parent.left == root && root.left == null && root.right == null) sum += root.val; } }}
阅读全文
0 0
- LeetCode 404 Sum of Left Leaves
- [LeetCode-404]Sum of Left Leaves(java)
- Leetcode 404 Sum of Left Leaves
- LeetCode[404] Sum of Left Leaves
- LeetCode #404: Sum of Left Leaves
- LeetCode 404 Sum of Left Leaves (DFS)
- leetcode 404 Sum of Left Leaves
- LeetCode #404 - Sum of Left Leaves - Easy
- leetcode 404 Sum of Left Leaves C++
- leetcode-404-Sum of Left Leaves
- leetcode 404 Sum of Left Leaves
- [Leetcode] #404 Sum of Left Leaves
- Leetcode #404 Sum of Left Leaves
- LeetCode 404:Sum of Left Leaves
- LeetCode 404 Sum of Left Leaves
- Sum of Left Leaves ---LeetCode
- Leetcode Sum of Left Leaves
- LEETCODE--Sum of Left Leaves
- Azure: Custom Docker Image support SSH on Web App on Linux
- ST188光电式传感器的应用
- angular元素操作篇
- 大数据系统数据采集产品的架构分
- 用ireport生成二维码及去除二维码白边
- LeetCode 404:Sum of Left Leaves
- 移动设备渲染实时阴影
- caffe配置笔记
- 对话框样式Activity获得窗口外点击事件
- 图像处理之调整亮度与对比度
- 备份和恢复概念+逻辑备份+脱机备份(冷备份)+联机备份(热备份)+物理备份概念+完全数据库脱机备份+部分数据库脱机备份+部分数据库联机备份+逻辑备份概念
- git--版本工具的常用命令以及初始化实操
- Linux下开启多个数据库实例的步骤
- jhipster微服务--简单demo