
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
Given two 1d vectors, implement an iterator to return their elements alternately.
Example:
Follow up: What if you are given
k
1d vectors? How well can your code be extended to such cases?Clarification for the follow up question:
The "Zigzag" order is not clearly defined and is ambiguous for
k > 2
cases. If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic". For example:这道题让我们写一个之字形迭代器,跟之前那道 Flatten 2D Vector 有些类似,那道题是横向打印,这道题是纵向打印,虽然方向不同,但是实现思路都是大同小异。博主最先想到的方法是用两个变量i和j分别记录两个向量的当前元素位置,初始化为0,然后当 i<=j 时,则说明需要打印 v1 数组的元素,反之则打印 v2 数组中的元素。在 hasNext 函数中,当i或j打印等于对应数组的长度时,将其赋为一个特大值,这样不影响打印另一个数组的值,只有当i和j都超过格子数组的长度时,返回 false,参见代码如下:
解法一:
下面来看另一种解法,这种解法直接在初始化的时候就两个数组按照之字形的顺序存入另一个一位数组中了,那么就按顺序打印新数组中的值即可,参见代码如下:
解法二:
由于题目中的 Follow up 让将输入换成k个数组的情况,那么上面的解法一就不适用了,解法二的空间复杂度比较高,所以需要一种更高效的方法。这里可以采用 queue 加 iterator 的方法,用一个 queue 里面保存 iterator 的 pair,在初始化的时候,有几个数组就生成几个 pair 放到 queue 中,每个 pair 保存该数组的首位置和尾位置的 iterator,在 next() 函数中,取出 queue 队首的一个 pair,如果当前的 iterator 不等于 end(),将其下一个位置的 iterator 和 end 存入队尾,然后返回当前位置的值。在 hasNext() 函数中,只需要看 queue 是否为空即可,参见代码如下:
解法三:
Github 同步地址:
#281
类似题目:
Flatten 2D Vector
参考资料:
https://leetcode.com/problems/zigzag-iterator/
https://leetcode.com/problems/zigzag-iterator/discuss/71781/Short-Java-O(1)-space
https://leetcode.com/problems/zigzag-iterator/discuss/71779/Simple-Java-solution-for-K-vector
https://leetcode.com/problems/zigzag-iterator/discuss/71835/C%2B%2B-with-queue-(compatible-with-k-vectors)
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: