
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 an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
For example, given a
3-ary
tree:We should return its level order traversal:
Note:
1000
.5000
.这道题给了我们一棵N叉树,让我们对其进行层序遍历。我们做过之前二叉树的层序遍历的那道题的话Binary Tree Level Order Traversal,那么这道题也就不难了。虽说现在每一个结点可能有很多个子结点,但其实处理的思路的都是一样的。子结点放到了一个children数组中,我们访问的时候只要遍历数组就行了。先来看迭代的写法,用到了队列queue来辅助,首先判断root是否为空,为空直接返回空数组,否则加入queue中。然后遍历queue,这里用的trick就是,要加个for循环,要将当前queue中的结点的个数统计下来,因为再加入下一层的结点时,queue的结点个数会增加,而在加入下一层结点之前,当前queue中的结点个数全都属于一层,所以我们要把层与层区分开来,将同一层的结点都放到一个数组out中,之后再放入结果res中,这种层序遍历的思想在迷宫遍历找最短路径的时候应用的也很多,是个必须要掌握的方法呢,参见代码如下:
解法一:
下面再来看递归的写法,其实层序遍历天然适合迭代的写法,但我们强行递归也是可以的,就是有点秀。由于递归DFS的设定是一条路走到黑再返回,那么必然会跨越不同的层数,所以为了区别当前的层,我们需要一个变量level来标记当前的层数,根结点root就是第0层,依此类推往上加。然后还有个trick就是关于结果res的大小,由于我们并不知道树的深度,所以一旦我们遍历的层数超过了当前res的大小,我们需要resize一下,这样才不会出错。之后,我们将当前遍历到的结点加到res中的第level层中,然后遍历子结点数组,对每一个子结点调用递归函数即可,参见代码如下:
解法二:
类似题目:
Binary Tree Level Order Traversal
N-ary Tree Preorder Traversal
N-ary Tree Postorder Traversal
参考资料:
https://leetcode.com/problems/n-ary-tree-level-order-traversal/description/
https://leetcode.com/problems/n-ary-tree-level-order-traversal/discuss/156218/Typical-C++-recursive-solution
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: