Skip to content

Latest commit

 

History

History
21 lines (21 loc) · 492 Bytes

530. Minimum Absolute Difference in BST.md

File metadata and controls

21 lines (21 loc) · 492 Bytes
class Solution {
public:
    int getMinimumDifference(TreeNode* root) {
        stack<TreeNode*> s;
        int mn = INT_MAX, pre = -100000;
        while (root || !s.empty())  {
            while (root) {
                s.push(root);
                root = root->left;
            }
            root = s.top(); s.pop();
            int cur = root->val;
            mn = min(mn, cur - pre);
            pre = cur;
            root = root->right;
        }
        return mn;
    }
};