MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / Next

Method Next

flatten_nested_list_iterator_341/solution.go:108–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108func (this *NestedIterator) Next() int {
109 current := this.stack.Peek()
110 for !current.List[current.Idx].IsInteger() {
111 next := &ListIndex{
112 Idx: 0,
113 List: current.List[current.Idx].GetList(),
114 }
115 this.stack.Push(next)
116
117 current.Idx++
118 current = next
119 }
120
121 value := current.List[current.Idx].GetInteger()
122 current.Idx++
123
124 if current.Idx == len(current.List) {
125 this.stack.Pop()
126 }
127
128 return value
129}
130
131func (this *NestedIterator) HasNext() bool {
132 return !this.stack.IsEmpty() && this.stack.Peek().Idx != len(this.stack.Peek().List)

Callers 1

TestIteratorFunction · 0.45

Calls 6

PeekMethod · 0.80
IsIntegerMethod · 0.80
GetListMethod · 0.80
GetIntegerMethod · 0.80
PushMethod · 0.45
PopMethod · 0.45

Tested by 1

TestIteratorFunction · 0.36