File tree Expand file tree Collapse file tree 1 file changed +0
-17
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-17
lines changed Original file line number Diff line number Diff line change 4
4
import java .util .LinkedList ;
5
5
import java .util .Queue ;
6
6
7
- /**
8
- * 284. Peeking Iterator
9
- *
10
- * Given an Iterator class interface with methods: next() and hasNext(),
11
- * design and implement a PeekingIterator that support
12
- * the peek() operation -- it essentially peek() at the element that will be returned by the next call to next().
13
-
14
- Here is an example. Assume that the iterator is initialized to the beginning of the queue: [1, 2, 3].
15
-
16
- Call next() gets you 1, the first element in the queue.
17
-
18
- Now you call peek() and it returns 2, the next element. Calling next() after that still return 2.
19
-
20
- You call next() the final time and it returns 3, the last element. Calling hasNext() after that should return false.
21
-
22
- Follow up: How would you extend your design to be generic and work with all types, not just integer?
23
- */
24
7
public class _284 {
25
8
public static class Solution1 {
26
9
public static class PeekingIterator implements Iterator <Integer > {
You can’t perform that action at this time.
0 commit comments