1 public boolean isSameTree(TreeNode p, TreeNode q) { 2 if (p==null&&q==null)return true; 3 if (p==null||q==null)return false; 4 return check(p, q); 5 } 6 7 boolean check(TreeNode s, TreeNode t) { 8 if (s == null && t == null) return true; 9 if (s == null || t == null) return false; 10 if (s.val == t.val) { 11 return check(s.left, t.left) && check(s.right, t.right); 12 } 13 return false; 14 }