Back to course home
0% completed
Vote For New Content
Solution: Zigzag Iterator
Problem Statement
Given two 1d
vectors, implement an iterator to return their elements alternately.
Implement the Solution
class:
Solution(List<int> v1, List<int> v2)
is a constructor.- int
next()
returns the current element of the iterator and moves the iterator to the next element. - boolean
hasNext()
returns true if the iterator still has elements, and false otherwise.
Examples
Example 1
- Input: V1 = [1,2], v2 = [3,4,5,6]
- Expected Output: [1,3,2,4,5,6]
- Explanation: The elements will be returned in [1,3,2,4,5,6] order when we make v1
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page