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;
}
};