Can someone help me find bugs?


  • 0
    S

    There is my code:

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

    53 / 54 test cases passed.
    Can someone tell me why the code is wrong.
    Thank you guys!


Log in to reply
 

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