One-line solution in C


  • 0
    M
    bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
        // if (p && q)
        //     return (isSameTree(p->left, q->left) && isSameTree(p->right, q->right) && (p->val == q->val)? true : false);
        // else if(!p && !q)
        //     return true;
        // else
        //     return false;
            
        return ((p && q) && (isSameTree(p->left, q->left) && isSameTree(p->right, q->right) && (p->val == q->val)? true : false)) || (!p && !q);
    }

  • 2
    P

    why do you have the "(cond) ? true : false" ?
    it returns a boolean already


  • 0
    M

    That was a mistake. You're right.


Log in to reply
 

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