mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-22 21:43:08 +03:00
17 lines
383 B
C
17 lines
383 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);
|
|
}
|