0284. Peeking Iterator
Description
**Input**
["PeekingIterator", "next", "peek", "next", "next", "hasNext"]
[[[1, 2, 3]], [], [], [], [], []]
**Output**
[null, 1, 2, 2, 3, false]
**Explanation**
PeekingIterator peekingIterator = new PeekingIterator([1, 2, 3]); // [**1**,2,3]
peekingIterator.next(); // return 1, the pointer moves to the next element [1,**2**,3].
peekingIterator.peek(); // return 2, the pointer does not move [1,**2**,3].
peekingIterator.next(); // return 2, the pointer moves to the next element [1,2,**3**]
peekingIterator.next(); // return 3, the pointer moves to the next element [1,2,3]
peekingIterator.hasNext(); // return Falseac
Last updated