leetcode 404 Sum of Left Leaves C++
2016-12-27 20:18
363 查看
前序遍历
int sum;
int sumOfLeftLeaves(TreeNode* root) {
if(!root) return 0;
if(root->left) {
if (!root->left->left && !root->left->right) {
sum += root->left->val;
}
}
if (root->left) sumOfLeftLeaves(root->left);
if (root->right) sumOfLeftLeaves(root->right);
return sum;
}
int sum;
int sumOfLeftLeaves(TreeNode* root) {
if(!root) return 0;
if(root->left) {
if (!root->left->left && !root->left->right) {
sum += root->left->val;
}
}
if (root->left) sumOfLeftLeaves(root->left);
if (root->right) sumOfLeftLeaves(root->right);
return sum;
}
相关文章推荐
- leetcode 404 Sum of Left Leaves
- LeetCode 404 Sum of Left Leaves
- leetcode404: Sum of Left Leaves
- LeetCode@HashMap_404_Sum_of_Left_Leaves
- 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(java实现)
- [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
- LeetCode@Tree_404_Sum_of_Left_Leaves
- 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