Java solution 0 ms by 3 lines


  • 0
    public boolean isSameTree(TreeNode p, TreeNode q) {
        while(p != null && q != null) 
          return p.val != q.val ? false : isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        return p == null && q == null;
    }

Log in to reply
 

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