c++ recursion


  • 0
    class Solution {
    public:
        bool isSameTree(TreeNode* p, TreeNode* q) {
            
            if(!p && !q)
                return 1;
            
            if((!p && q) || (p && !q))
                return 0;
                
            if(p->val == q->val)
            {
                return(isSameTree(p->left,q->left) && isSameTree(p->right,q->right)); 
            }
            else
                return 0;
        }
    };
    

Log in to reply
 

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