Why should 'input [],0' return false? Isn't it true?


  • 0
    D

    why should 'input [],0' return false? Isn't it true?


  • 0
    D

    my Solution .

    class Solution {
    public:
    bool hasPathSum(TreeNode* root, int sum) {
    bool leftTree;
    bool rightTree;
    if(root==NULL&&sum==0)
    return true;
    else if(root==NULL && sum!=0)
    return false;

    leftTree=hasPathSum(root->left,sum-root->val)
    rightTree=hasPathSum(root->right,sum-root->val);
    return leftTree||rightTree;
    }
    

    };


  • 0

    I'd say it's "false" because that tree doesn't even have any root-to-leaf path at all.

    You can btw format code in comments just like you can in questions/answers, which would make it readable.


  • 0
    N

    The difference between None and 0.


Log in to reply
 

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