Accepted C Solution - Recursion


  • 0
    M
    bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
        struct TreeNode *nodep=p, *nodeq=q;
        bool ret;
        
        if((nodep == NULL) && (nodeq == NULL))
            return (1);
        else if((nodep == NULL) || (nodeq == NULL))
            return (0);
        
        if((nodep->val != nodeq->val))
            return (0);
        else
        {
            ret = isSameTree(nodep->left,nodeq->left);
            if(ret)
                ret = isSameTree(nodep->right,nodeq->right);
        }
        
        return (ret);
        
        
    }
    

Log in to reply
 

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