783. 二叉搜索树节点最小距离
C代码:二叉树
int min;
int pre;
int dfs(struct TreeNode* root) {
if (root == NULL) {
return;
}
dfs(root->left);
if (pre != -1) {
min = fmin(min, root->val - pre);
}
pre = root->val; // 中序遍历
dfs(root->right);
}
int minDiffInBST(struct TreeNode* root){
min = INT_MAX;
pre = -1;
dfs(root);
return min;
}