My 4ms C anwser


  • 0
    Z

    bool hasPathSum(struct TreeNode* root, int sum) {
    if (root==NULL)
    {
    return 0;
    }
    if ((root->left==NULL)&(root->right==NULL)&(root->val==sum))
    {
    return 1;
    }
    return (hasPathSum(root->left,sum-root->val)||hasPathSum(root->right,sum-root->val));


Log in to reply
 

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