251. Flatten 2D Vector
ArrayTwo PointersDesignIterator
Hints
Hint 1
How many variables do you need to keep track?
Hint 2
Two variables is all you need. Try with
x and y.Hint 3
Beware of empty rows. It could be the first few rows.
Hint 4
To write correct code, think about the invariant to maintain. What is it?
Hint 5
The invariant is
x and y must always point to a valid point in the 2d vector. Should you maintain your invariant ahead of time or right when you need it?Hint 6
Not sure? Think about how you would implement
hasNext(). Which is more complex?Hint 7
Common logic in two different places should be refactored into a common method.
Preparing judge…