TheAlgorithms-C/leetcode/src/404.c
2019-09-18 10:14:10 -07:00

15 lines
378 B
C

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);
}