Check subtree - Can anybody please tell what's missing in this problem?


  • 0
    S
    Can someone please tell what is missing here? Only 174/176 test cases passed.
    
    class Solution {
    public:
     
        bool isSubtree(TreeNode* s, TreeNode* t) {
                   
            if(s == NULL && t == NULL){
                return true;
            }
            
            if(s == NULL || t == NULL){
                return false;
            }
                               
            if((s->val == t->val) && isSubtree(s->left,t->left) && isSubtree(s->right,t->right))
                return true;
            
            if(isSubtree(s->left,t) || isSubtree(s->right,t)){
                return true;
            }
            
            return false;
                     
        }
    };
    

Log in to reply
 

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