Skip to content

Commit 3391c70

Browse files
committed
修复说明,将前序改为中序
1 parent 28586fa commit 3391c70

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

01.阿里篇/1.1.3 给定一个二叉搜索树(BST),找到树中第 K 小的节点.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Solution {
7979
8080
```
8181

82-
解法2:基于二叉搜索树的特性,在前序遍历的结果中,第k个元素就是本题的解。
82+
解法2:基于二叉搜索树的特性,在中序遍历的结果中,第k个元素就是本题的解。
8383
最差的情况是k节点是bst的最右叶子节点,不过`每个节点的遍历次数最多是1次`
8484
遍历并不是需要全部做完,使用计数的方式,找到第k个元素就可以退出。
8585
下面是go的一个简单实现。
@@ -115,7 +115,7 @@ func count(bst *BST, k int) int {
115115
return 0
116116
}
117117
118-
// countRecurisive 对bst使用前序遍历
118+
// countRecurisive 对bst使用中序遍历
119119
// 用计数方式控制退出遍历,参数c就是已遍历节点数
120120
func countRecursive(bst *BST, c *int, k int) (bool, int) {
121121
if bst.left != nil {

0 commit comments

Comments
 (0)