← 返回 goldmansachs 的题目列表Zigzag Iterator for Two 1D Vectors
类型:online_judge
goldmansachs
Given two 1D vectors v1 and v2, implement an iterator class ZigzagIterator to return elements from these two vectors alternately. The next() method should return the next element, and hasNext() should return true if there are more elements and false otherwise. You should iterate from both vectors alternately, taking elements one at a time, until all elements are used. If one vector is finished, just continue taking elements from the other vector.
Example
Input
[[1, 2], [3, 4, 5, 6]]