Need Help!!!!!!!!!!!!!!


  • 0
    K

    My code couldn't pass the test case [1,1] [1] . I know where it is breaking, but i don't know how to solve that . Can somebody help?

    class Solution {

     public boolean isSubtree(TreeNode s, TreeNode t) {
    	 if(s!=null && t!=null && s.val==t.val)
    		 return check(s,t);
    	 else if(s==null && t!=null || s!=null && t==null)
    		 return false;
    	 else if(s==null && t==null)
    		 return false;
    	 else
    		 return (isSubtree(s.left, t) || isSubtree(s.right, t));
        }
    
    private boolean check(TreeNode s, TreeNode t) {
    	if(s!=null && t!=null)
    	{
    		if(s.val==t.val)
    			return check(s.left,t.left) && check(s.right,t.right);
    	}
    	else if(s==null && t==null)
    		return true;
    	return false;
    }
    

    }


Log in to reply
 

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