File tree Expand file tree Collapse file tree 2 files changed +8
-8
lines changed
Algorithms/0173.binary-search-tree-iterator Expand file tree Collapse file tree 2 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 4
4
" ASCI" ,
5
5
" IDID" ,
6
6
" Icode" ,
7
+ " Inorder" ,
7
8
" Leet" ,
8
9
" Puerkito" ,
9
10
" Qedo" ,
Original file line number Diff line number Diff line change @@ -16,30 +16,29 @@ type TreeNode = kit.TreeNode
16
16
17
17
// BSTIterator is the iterator of BST
18
18
type BSTIterator struct {
19
- index * int
20
- nums * []int
19
+ index int
20
+ nums []int
21
21
}
22
22
23
23
// Constructor returns a BST iterator
24
24
func Constructor (root * TreeNode ) BSTIterator {
25
25
nums := convert (root )
26
- index := 0
27
26
return BSTIterator {
28
- index : & index ,
29
- nums : & nums ,
27
+ index : 0 ,
28
+ nums : nums ,
30
29
}
31
30
}
32
31
33
32
// Next returns the next smallest number
34
33
func (it * BSTIterator ) Next () int {
35
- res := ( * it .nums )[ * it .index ]
36
- * it .index ++
34
+ res := it .nums [ it .index ]
35
+ it .index ++
37
36
return res
38
37
}
39
38
40
39
// HasNext returns whether we have a next smallest number
41
40
func (it * BSTIterator ) HasNext () bool {
42
- return * it .index < len (* it .nums )
41
+ return it .index < len (it .nums )
43
42
}
44
43
45
44
func convert (root * TreeNode ) []int {
You can’t perform that action at this time.
0 commit comments