mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
更新0530.二叉搜索树的最小绝对值差.md迭代Java注释
This commit is contained in:
@ -184,15 +184,15 @@ class Solution {
|
|||||||
int result = Integer.MAX_VALUE;
|
int result = Integer.MAX_VALUE;
|
||||||
while (cur != null || !stack.isEmpty()) {
|
while (cur != null || !stack.isEmpty()) {
|
||||||
if (cur != null) {
|
if (cur != null) {
|
||||||
stack.push(cur);
|
stack.push(cur); // 将访问的节点放进栈
|
||||||
cur = cur.left; // 左节点入栈
|
cur = cur.left; // 左
|
||||||
}else {
|
}else {
|
||||||
cur = stack.pop(); // 右节点入栈
|
cur = stack.pop();
|
||||||
if (pre != null) {
|
if (pre != null) { // 中
|
||||||
result = Math.min(result, cur.val - pre.val);
|
result = Math.min(result, cur.val - pre.val);
|
||||||
}
|
}
|
||||||
pre = cur;
|
pre = cur;
|
||||||
cur = cur.right;
|
cur = cur.right; // 右
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Reference in New Issue
Block a user