https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/description/


class Solution {
int answer = 0;
public int maxAncestorDiff(TreeNode root) {
DFS(root, root.val, root.val);
return answer;
}
public void DFS(TreeNode node, int max, int min) {
if(node == null) {
return;
}
max = Math.max(max, node.val);
min = Math.min(min, node.val);
if (node.left == null && node.right == null) {
answer = Math.max(answer, max - min);
}
DFS(node.left, max, min);
DFS(node.right, max, min);
}
}