c++ 3ms


  • 0
    9
    class Solution {
        int sum=0;
    public:
        int sumOfLeftLeaves(TreeNode* root) {
            if(!root) return 0;
            if(root->left!=NULL&&root->left->left==NULL&&root->left->right==NULL)
                return root->left->val+sumOfLeftLeaves(root->right);
            else return sumOfLeftLeaves(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.