# 530. Minimum Absolute Difference in BST

Leetcode: <https://leetcode.com/problems/minimum-absolute-difference-in-bst/>

利用BST性质：`inorder` 遍历结果是 sorted array，最小的绝对值差肯定出现在这个 array 的两个相邻元素之间，那直接在`inorder`遍历时比较当前值与前值。

比较绕的部分是实现 iteratively in-order traversal.

```python
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def getMinimumDifference(self, root: TreeNode) -> int:
        minDiff = float("inf")
        prev = float("inf")
        stack = []
        
        while root or stack:
            if root:
                stack.append(root)
                root = root.left
            else:
                root = stack.pop()
                minDiff = min(minDiff, abs(root.val - prev))
                prev = root.val
                root = root.right
                
        return minDiff
```
