leetcode 404. Sum of Left Leaves

Orignal question can be found here.

My solution is as follows:

int sumOfLeftLeaves(struct TreeNode* root)
  int result = 0;
  int *result_p = &result;
  sumCore(root, 0, result_p);
  return result;

void sumCore(struct TreeNode* root, int flag, int *result_p)
  if(root == NULL)
  if(flag==1 && root->left==NULL && root->right==NULL)
      *result_p += root->val;
  if(root->left != NULL)
    sumCore(root->left, 1, result_p);
  if(root->right != NULL)
    sumCore(root->right, 0, result_p);

One thought on “leetcode 404. Sum of Left Leaves”

  1. I will right away take hold of your rss as I can’t find your email subscription hyperlink or e-newsletter service. Do you have any? Kindly let me understand so that I may just subscribe. Thanks.

Leave a Reply

Your email address will not be published.