2
* Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode3
* right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left,4
* TreeNode right) { this.val = val; this.left = left; this.right = right; } }7
public int maxAncestorDiff(TreeNode root) {9
if (root == null) return 0;11
return find(root, Integer.MAX_VALUE, Integer.MIN_VALUE);14
public int find(TreeNode root, int min, int max) {15
if (root == null) return Math.abs(max - min);17
min = Math.min(min, root.val);18
max = Math.max(max, root.val);20
return Math.max(find(root.left, min, max), find(root.right, min, max));