A C solution


  • 0
    D
    bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
        if(!p && !q)
            return 1;
        if(!(p&&q))
            return 0;
        if(p->val != q->val)
            return 0;
            
        return isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
    }
    

Log in to reply
 

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