LeetCode 404. 左叶子之和
题目链接:https://leetcode-cn.com/problems/sum-of-left-leaves/
计算给定二叉树的所有左叶子之和。
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * struct TreeNode *left; 6 * struct TreeNode *right; 7 * }; 8 */ 9 10 int sumOfLeftLeaves(struct TreeNode* root){ 11 if(root==NULL) return 0; 12 if(root->left!=NULL&&root->left->left==NULL&&root->left->right==NULL) return root->left->val+sumOfLeftLeaves(root->right); 13 return sumOfLeftLeaves(root->left)+sumOfLeftLeaves(root->right); 14 }