TheAlgorithms-C/leetcode/src/404.c

15 lines
378 B
C
Raw Normal View History

2019-09-19 01:14:10 +08:00
bool isleaf(struct TreeNode *root) {
return root->left == NULL && root->right == NULL;
}
int sumOfLeftLeaves(struct TreeNode* root){
if (root == NULL)
return 0;
if (root->left) {
if(isleaf(root->left))
return root->left->val + sumOfLeftLeaves(root->right);
}
return sumOfLeftLeaves(root->left) + sumOfLeftLeaves(root->right);
}