Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 773 Bytes

530.md

File metadata and controls

9 lines (5 loc) · 773 Bytes

530. Minimum Absolute Difference in BST

Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

We can easily see that the minimum diff between the value of the nodes is the adjacent node. Thus, it must be the diff between one of itself - one of the children. So we can record the value of the previous dfs root node and make a diff.

The coplilot almost wrote all of the code. It's definetly wrong. The real diff shall be the leftmost one in the right tree with the root node. So we need to get the maximal value of the left tree and get the minimal value of right tree, and minus the root node value to calcualte the res value.

Yes. AC! no extra space but expensive time cost.