← 返回 openai 的题目列表Resumable 2D Iterator with Pause and Resume Functionality
类型:online_judge
openai
Design a 2D resumable iterator. Implement a class ResumableIterator with the following methods:
next(): Returns the next element in the sequence.
hasNext(): Returns true if there are more elements to iterate, otherwise returns false.
resume(): Resumes iteration from the last stopped point.
Requirements:
The sequence can be mutable.
Operations should be time efficient.
Example:
# Input:
vectors = [[1,2], [3], [4,5,6]]
iterator = ResumableIterator(vectors)
results = []
while iterator.hasNext():
results.append(iterator.next())
if len(results) == 2:
break
iterator.resume() # Continue from where it was interrupted
# Output: results = [1, 2, 3, 4, 5, 6]
Constraints:
Each sub-list contains at most 1000 integers.
Total integers count 10000.
Other parts of the interface should be implemented by yourself.
Example
Input
[[1, 2], [3], [4, 5, 6]]