284. Peeking Iterator


https://leetcode.com/problems/peeking-iterator/



Runtime: 0 ms, faster than 100.00% of Go online submissions for Peeking Iterator.
Memory Usage: 2.6 MB, less than 29.55% of Go online submissions for Peeking Iterator.



```
type PeekingIterator struct {
	//8:54
	list []int
	length int
	index int
	//8:58
}

func Constructor(iter *Iterator) *PeekingIterator {
	list := make([]int, 0)
	for iter.hasNext() {
		list = append(list, iter.next())
	}
	return &PeekingIterator{list: list, length: len(list),index: -1}
}

func (this *PeekingIterator) hasNext() bool {
	if this.index < this.length-1 {
		return true
	} else {
		return false
	}
}

func (this *PeekingIterator) next() int {
	this.index += 1
	return this.list[this.index]
}

func (this *PeekingIterator) peek() int {
	return this.list[this.index + 1]
}
```
