Given two 1d vectors, implement an iterator to return their elements alternately.
For example, given two 1d vectors:
v1 = [1, 2] v2 = [3, 4, 5, 6]
By callingnextrepeatedly untilhasNextreturnsfalse, the order of elements returned bynextshould be:[1, 3, 2, 4, 5, 6].
Follow up: What if you are givenk1d vectors? How well can your code be extended to such cases?
setfan 大神的code!!! ,膜拜, 用个临时变量 swap iter1 和2. 我用了一个flag 变量检查是否应该从iter1 开始, 关于follow up 问题, 有一个大神用了linkedList, 拿出来, 放进去的淘腾, 其实用queue 更直观, idea 有了, 代码不难, 就不贴了。