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 44 " ASCI" ,
55 " IDID" ,
66 " Icode" ,
7+ " Inorder" ,
78 " Leet" ,
89 " Puerkito" ,
910 " Qedo" ,
Original file line number Diff line number Diff line change @@ -16,30 +16,29 @@ type TreeNode = kit.TreeNode
1616
1717// BSTIterator is the iterator of BST
1818type BSTIterator struct {
19- index * int
20- nums * []int
19+ index int
20+ nums []int
2121}
2222
2323// Constructor returns a BST iterator
2424func Constructor (root * TreeNode ) BSTIterator {
2525 nums := convert (root )
26- index := 0
2726 return BSTIterator {
28- index : & index ,
29- nums : & nums ,
27+ index : 0 ,
28+ nums : nums ,
3029 }
3130}
3231
3332// Next returns the next smallest number
3433func (it * BSTIterator ) Next () int {
35- res := ( * it .nums )[ * it .index ]
36- * it .index ++
34+ res := it .nums [ it .index ]
35+ it .index ++
3736 return res
3837}
3938
4039// HasNext returns whether we have a next smallest number
4140func (it * BSTIterator ) HasNext () bool {
42- return * it .index < len (* it .nums )
41+ return it .index < len (it .nums )
4342}
4443
4544func convert (root * TreeNode ) []int {
You can’t perform that action at this time.
0 commit comments