Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87754d3

Browse files
committed
173 accepted. 44ms
1 parent 4e92e7e commit 87754d3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ASCI",
55
"IDID",
66
"Icode",
7+
"Inorder",
78
"Leet",
89
"Puerkito",
910
"Qedo",

Algorithms/0173.binary-search-tree-iterator/binary-search-tree-iterator.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,29 @@ type TreeNode = kit.TreeNode
1616

1717
// BSTIterator is the iterator of BST
1818
type BSTIterator struct {
19-
index *int
20-
nums *[]int
19+
index int
20+
nums []int
2121
}
2222

2323
// Constructor returns a BST iterator
2424
func 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
3433
func (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
4140
func (it *BSTIterator) HasNext() bool {
42-
return *it.index < len(*it.nums)
41+
return it.index < len(it.nums)
4342
}
4443

4544
func convert(root *TreeNode) []int {

0 commit comments

Comments
 (0)