In-order traversal of BST yields sorted sequence. So, we just need to subtract the previous element from the current one, and keep track of the minimum. We need O(1) memory as we only store the previous element, but we still need O(h) for the stack.

```
void inorderTraverse(TreeNode* root, int& val, int& min_dif) {
if (root->left != NULL) inorderTraverse(root->left, val, min_dif);
if (val >= 0) min_dif = min(min_dif, root->val - val);
val = root->val;
if (root->right != NULL) inorderTraverse(root->right, val, min_dif);
}
int getMinimumDifference(TreeNode* root) {
auto min_dif = INT_MAX, val = -1;
inorderTraverse(root, val, min_dif);
return min_dif;
}
```

Another solution with the member variables (6 lines):

```
class Solution {
int min_dif = INT_MAX, val = -1;
public:
int getMinimumDifference(TreeNode* root) {
if (root->left != NULL) getMinimumDifference(root->left);
if (val >= 0) min_dif = min(min_dif, root->val - val);
val = root->val;
if (root->right != NULL) getMinimumDifference(root->right);
return min_dif;
}
```