
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 a binary tree, determine if it is a complete binary tree.
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
Example 1:
Example 2:
Note:
这道题给了一棵二叉树,让我们判断是否是一棵完全二叉树 Complete Binary Tree,通过题目中的解释可知,完全二叉树除了最后一行之外,所有位置都是满员的,而且最后一行的结点都是尽可能靠左的,注意跟完满二叉树 Full Bianry Tree 区分开来。最简单直接的方法就是按层序遍历二叉树,当遇到空结点时,后面若还出现非空结点,则一定不是完全二叉树。具体到写法就是先把根结点放入到队列中,然后进行循环,条件是队首结点不为空。在循环中取出队首结点,然后将其左右子结点加入队列中,这里不必判断子结点是否为空,为空照样加入队列,因为一旦取出空结点,循环就会停止。然后再用个循环将队首所有的空结点都移除,这样若是完全二叉树的话,队列中所有还剩的结点都应该是空结点,且都会被移除,若队列中存在非空结点,说明不是完全二叉树,最后只要判断队列是否为空即可,参见代码如下:
解法一:
下面这种解法思想都一样,只不过写法略有不同,这里使用了一个变量 found,初始化为 false,然后还是用层序遍历,当取出的结点为空结点时,比较 found 为 true,然后继续遍历。当遍历到非空结点时,若此时 found 为 true 了,则直接返回 false 即可。当循环退出后,返回 true, 参见代码如下:
解法二:
Github 同步地址:
#958
参考资料:
https://leetcode.com/problems/check-completeness-of-a-binary-tree/
https://leetcode.com/problems/check-completeness-of-a-binary-tree/discuss/205682/JavaC%2B%2BPython-BFS-Level-Order-Traversal
https://leetcode.com/problems/check-completeness-of-a-binary-tree/discuss/205768/Java-easy-Level-Order-Traversal-one-while-loop
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: