C++ AC code with using only given function


  • 0
    K

    '''
    class Solution {
    public:

    int sumNumbers(TreeNode* root , int currentSum = 0) {
        if (root == NULL)
            return 0;
        if (root->left == NULL && root->right == NULL)
            return currentSum * 10 + root->val;
        
        return sumNumbers(root->left , currentSum * 10 + root->val)
                + sumNumbers(root->right , currentSum * 10 + root->val);
    }
    

    };
    '''


Log in to reply
 

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