404. Sum of Left Leaves
2016-12-28 09:30
274 查看
Find the sum of all left leaves in a given binary tree.
Example:
LeetCode AC代码:
Example:
3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
LeetCode AC代码:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: int sumOfLeftLeaves(TreeNode* root) { if (root == NULL) return 0; if (root->left && root->left->left == NULL && root->left->right == NULL) return root->left->val + sumOfLeftLeaves(root->right); return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right); } };
相关文章推荐
- 404. Sum of Left Leaves
- 【Leetcode】404. Sum of Left Leaves
- 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
- leetcode404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- LeetCode oj 404. Sum of Left Leaves (DFS||BFS)
- leetcode_404. Sum of Left Leaves-左叶子的和
- [leetcode: Python]404. Sum of Left Leaves
- 404. Sum of Left Leaves求树的所有左叶子节点的和
- 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