Given two vectors of integers v1 and v2, implement an iterator to return their elements alternately.
Implement the ZigzagIterator class:
- ZigzagIterator(List
v1, List v2) initializes the object with the two vectors v1 and v2. - boolean hasNext() returns true if the iterator still has elements, and false otherwise.
- int next() returns the current element of the iterator and moves the iterator to the next element.
- Time : O(n)
- Space : O(nm)
c++
1 | class ZigzagIterator { |
- Time : O(nm)
- Space : O(nm)
c++
1 | class ZigzagIterator { |