75-days-dsa-challenge

Ninja technique🥷 to ACE DSA Interviews.

View the Project on GitHub

404. Sum of Left Leaves

Solution

Code

class Solution {
private:
    int sum = 0;

public:
    int sumOfLeftLeaves(TreeNode* root, bool isLeft = false)
    {
        if (root == NULL) return 0;
        if (isLeft && root->left == NULL && root->right == NULL) sum += root->val;
        sumOfLeftLeaves(root->left, true);
        sumOfLeftLeaves(root->right, false);
        return sum;
    }
};