284. Peeking Iterator


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



Runtime: 21 ms, faster than 12.64% of Go online submissions for Add Two Numbers II.
Memory Usage: 6 MB, less than 8.05% of Go online submissions for Add Two Numbers II.



```python
class PeekingIterator:
    def __init__(self, iterator):
        """
        Initialize your data structure here.
        :type iterator: Iterator
        """
        #8:39
        self.list = []
        while iterator.hasNext():
            self.list.append(iterator.next())
        #print(self.list)
        self.index = -1
        #8:41
        #debug until 8:49
        

    def peek(self):
        """
        Returns the next element in the iteration without advancing the iterator.
        :rtype: int
        """
        return self.list[self.index+1]
        

    def next(self):
        """
        :rtype: int
        """
        self.index += 1
        return self.list[self.index]
        

    def hasNext(self):
        """
        :rtype: bool
        """
        if (self.index < len(self.list)-1):
            return True
        else:
            return False```
