[leetcode]: 404. Sum of Left Leaves
来源:互联网 发布:37龙神契约进阶数据 编辑:程序博客网 时间:2024/05/29 03:41
1.题目描述
Find the sum of all left leaves in a given binary tree.
Example:
3/ \9 20 / \ 15 7
There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
求一棵二叉树所有左叶子节点的和
2.分析
注意:1)左 2)叶子结点
3.代码
int sumOfLeftLeaves(TreeNode* root) { if (root == NULL) return 0; if(root->left!=NULL&&root->left->left==NULL&&root->left->right==NULL)//左节点是叶子节点 return root->left->val+ sumOfLeftLeaves(root->right); return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right); }
阅读全文
0 0
- LeetCode笔记:404. Sum of Left Leaves
- 【leetcode】404. Sum of Left Leaves【E】
- LeetCode—404. Sum of Left Leaves
- [LeetCode]404. Sum of Left Leaves
- Leetcode 404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- 404. Sum of Left Leaves - leetcode
- [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
- leetcode 404. Sum of Left Leaves
- leetcode(88).404. Sum of Left Leaves
- 【LeetCode】 404. Sum of Left Leaves
- leetcode 404. Sum of Left Leaves
- [Leetcode]404. Sum of Left Leaves
- 机器学习之特征工程
- 算法导论读书笔记(11)散列表
- STL之stack容器
- mysql count 优化
- 553. Optimal Division
- [leetcode]: 404. Sum of Left Leaves
- Servlet编程
- 代码动态加载Prefab预设体
- 机器学习知识点(二十四)隐马尔可夫模型HMM维特比Viterbi算法Java实现
- eclipse常用快捷键(不定期增加)
- TT--TTOtherPayManager(iOS微信和支付宝支付)
- mac 自带的 Apache 不支持 php
- 删除有序数组中的重复元素,并返回数组的新长度
- linux下devicetree中惯用的of函数