284. Peeking Iterator


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



Runtime: 76 ms, faster than 80.00% of TypeScript online submissions for Peeking Iterator.
Memory Usage: 41 MB, less than 40.00% of TypeScript online submissions for Peeking Iterator.



```typescript
class PeekingIterator {
    list: number[]
    index: number
    constructor(iterator: Iterator) {
        //9:02
        this.list = []
        while (iterator.hasNext()) {
            this.list.push(iterator.next())
        }
        this.index = -1
        //9:04
        //debug until 9:07
    }

    peek(): number {
        return this.list[this.index + 1]
    }

    next(): number {
        this.index += 1
        return this.list[this.index]
    }

    hasNext(): boolean {
        if (this.index < this.list.length - 1) {
            return true
        } else {
            return false
        }
    }
}
```
