404. Sum of Left Leaves(C语言)
来源:互联网 发布:欧阳娜娜 知乎 编辑:程序博客网 时间:2024/06/03 19:10
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. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int sumOfLeftLeaves(struct 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
- 404. Sum of Left Leaves(C语言)
- LetCode 404. Sum of Left Leaves (C++)
- LeetCode 404. Sum of Left Leaves 题解(C++)
- 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
- Java复习——接口
- 枚举【C#】
- Server端Scrapy抓博客并用Django变自己博客
- 表的表空间在users和在system下的区别
- 1.Python基础要点(二)
- 404. Sum of Left Leaves(C语言)
- ubuntn16.04LTS 初试 docker
- Dagger 2从浅到深(七)
- MyBatis_6
- 随机数
- Java集合类型详解
- C++课程笔记(3)——Part2 Abstraction Mechanisms
- Python中Str类的常用方法
- install_name_tool解决dyld: Library not loaded