Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def maxAncestorDiff(root: TreeNode) -> int:
- if root is None:
- return 0
- def _maxAncestorDiff(root, curMin, curMax):
- if root is None:
- return curMax - curMin
- curMin = min(root.val, curMin)
- curMax = max(root.val, curMax)
- leftTree = _maxAncestorDiff(root.left, curMin, curMax)
- rightTree = _maxAncestorDiff(root.right, curMin, curMax)
- return max(leftTree, rightTree)
- return _maxAncestorDiff(root, root.val, root.val)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement