mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
15 lines
378 B
C
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);
|
|
|
|
}
|