easy to understand c++ code dfs;


  • 0
    J

    '''class Solution {
    public:
    int sumOfLeftLeaves(TreeNode* root) {
    if(!root)
    return 0;
    int sum=0;
    if(root->left&&root->left->left==NULL&&root->left->right==NULL)
    sum+=root->left->val;
    int left=sumOfLeftLeaves(root->left);
    int right=sumOfLeftLeaves(root->right);
    sum+=left;
    sum+=right;
    return sum;

    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.