The last case is wrong?i dont know why


  • 0
    T

    public class Solution {
    boolean a;
    public Solution(){
    a=true;
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p==null )
        {
            if(q==null)
                return true;
            else{
                return false;
            }
            
        }else{
            if(q==null)
            return false;
            if(p.val!=q.val)
            return false;
        }
        
        
        if(p.left!=null )
        {
            if( q.left!=null){
                if(p.val==q.val){
                   a= isSameTree(p.left,q.left);
                }else
                return false;
            }else
                return false;
        } 
         else{
             if( q.left==null)
                { 
        
                     if(p.right!=null  )
                    {
                        if(q.right!=null){
                            if(p.val==q.val)
                                a=isSameTree(p.right,q.right);
                            else
                                return false;
                            
                        }
                    }  else{
                         if( q.right==null)
                            return true;
                         else 
                            return false;
                     }      
            
            }
             else 
                return false;
         }
         
       
            
            return a;
    }
    

    }


Log in to reply
 

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