Why it doesn't work?


  • 0
    N

    Does anyone know why my code doesn't work?

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

    Input:
    [10,5,15]
    [10,5,null,null,15]
    Output:
    true
    Expected:
    false


Log in to reply
 

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