← 返回 linkedin 的题目列表Implement a Custom Iterator
类型:online_judge
Implement a custom iterator with hasNext() and next() methods.
Requirements
hasNext(): Returns whether the iterator has a next element.
next(): Returns the next element.
Assume the input is an array of integers.
Example
# Input
iter = CustomIterator([1, 2, 3])
# Process
assert iter.hasNext() == True
assert iter.next() == 1
assert iter.hasNext() == True
assert iter.next() == 2
assert iter.hasNext() == True
assert iter.next() == 3
assert iter.hasNext() == False
Constraints
The length of the array n does not exceed 10^5.
Ensure your code is efficient and no need to consider multithreading.
Example
Input
[1, 2, 3]