minDistance
to MAX_VALUE
and prevValue
to None
.inOrder
that takes a node as an argument.None
, return immediately.inOrder
on the left child of the node.prevValue
is not None
, update minDistance
with the minimum of the current minDistance
and the difference between the node's value and prevValue
.prevValue
to the current node's value.inOrder
on the right child of the node.inOrder
on the root node to start the traversal.minDistance
after the traversal is complete.