
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.
We are given the head node
root
of a binary tree, where additionally every node's value is either a 0 or a 1.Return the same tree where every subtree (of the given tree) not containing a 1 has been removed.
(Recall that the subtree of a node X is X, plus every node that is a descendant of X.)
Note:
100 nodes
.0
or1
.这道题给了我们一棵二叉树,说是结点只有0或者1,让我们移除所有没有含有结点1的子树。题目中也给了一些图例,不难理解。这道题的难点就在于怎么看待没有结点1的子树,我们知道子树也是由一个个结点组成的,需要明确的是一个单独的叶结点也可算作是子树,所以值为0的叶结点一定要移除,就像上面的例子1和3中的几个叶结点要被移除一样。对于例子2来说,如果移除了第三行的3个叶结点后,那么第二行的那个值为0的结点也变成了叶结点,继续移除即可,所以与其找值全为0的子树,我们可以不断的移除值为0的叶结点,全都移除后那么值全为0的子树也就都被移除了。
好,想通了这一点后,我们看如何来实现。对于玩二叉树的题,十有八九都是用递归,所以我们应该首先就考虑递归的解法,然后再想按什么顺序来遍历二叉树呢?层序,先序,中序,还是后序?根据这道题的特点,我们要从末尾来一层一层的移除值为0的叶结点,所以天然时候用后序遍历。那么想到这里,解题思路跃然纸上了吧,我们首先对结点判空,如果不存在,直接返回空。然后分别对左右子结点调用递归函数,此时判断,如果当前结点是值为1的叶结点,那么移除该结点,即返回空,否则返回原结点即可,参见代码如下:
参考资料:
https://leetcode.com/problems/binary-tree-pruning/
https://leetcode.com/problems/binary-tree-pruning/discuss/122730/C++JavaPython-Self-Explaining-Solution-and-2-lines
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: