Python Explain Code
#Python program
class TreeNode: def __init__(self, key): self.key = key self.left = None self.right = Nonedef findMaxDifference(root, diff=float('-inf')): if root is None: return float('inf'), diff leftVal, diff = findMaxDifference(root.left, diff) rightVal, diff = findMaxDifference(root.right, diff) currentDiff = root.key - min(leftVal, rightVal) diff = max(diff, currentDiff)
return min(min(leftVal, rightVal), root.key), diff
root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])