← 返回 coinbase 的题目列表Flatten Iterator for Vector of Iterators with getnext() and hasnext() Methods
类型:online_judge
coinbase
Implement an iterator that takes a vector<iterator> as input. Implement the following methods:
getnext(): Returns the next element.
hasnext(): Checks if there are more elements available for iteration.
The provided iterators may be empty.
Test Case:
vec_of_iters = [[1, 2, 3], [4, 5], [6, 7, 8, 9]]
output = []
while iterator.hasnext():
output.append(iterator.getnext())
assert output == [1, 2, 3, 4, 5, 6, 7, 8, 9]
Example
Input
{'vec_of_iters': [[1, 2, 3], [4, 5], [6, 7, 8, 9]]}