Peeking Iterator – Leetcode Java | Welkin Lan
next() and hasNext() peek() operation — it essentially peek() at the element that will be returned by the next call to next(). Here is an example. Assume that the iterator is initialized to the beginning of the list: [1, 2, 3] Now you call next() You call next() the final time and it returns 3, the last element. Calling hasNext() A: // Java Iterator interface reference: // https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html class PeekingIterator implements IteratorRead full article from Peeking Iterator – Leetcode Java | Welkin Lan
No comments:
Post a Comment