C++ easy understand


  • 0
    F
    int sumOfLeftLeaves(TreeNode* root) {
        if(!root) return 0;
        return helper(root->left) + sumOfLeftLeaves(root->right);
    }
    int helper(TreeNode* root){
        if(!root) return 0;
        if(!root->left && !root->right) return root->val;
        return helper(root->left) + sumOfLeftLeaves(root->right);
    }

Log in to reply
 

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