1 2 3 4 5 6 7 8 9 10 11 12
|
public class SameTree { public boolean isSameTree(TreeNode p, TreeNode q) { return p == q || helper(p, q); } private boolean helper(TreeNode p, TreeNode q) { return (p == null && q == null) || !((p == null) || (q == null) || p.val != q.val) && helper(p.left, q.left) && helper(p.right, q.right); } }
|