
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.
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.
The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pairs that don't affect the one-to-one mapping relationship between the string and the original binary tree.
Example 1:
Example 2:
这道题给我们了一个二叉树,让我们创建对应的字符串,之前有一道正好反过来的题Construct Binary Tree from String。对于二叉树的处理,递归肯定是王道啊。想想如何来实现递归函数,我们观察到题目中的例子,发现如果左子结点为空,右子结点不为空时,需要在父结点后加上个空括号,而右子结点如果不存在,或者左右子结点都不存在就不需要这么做。那我们在递归函数中,如果当前结点不存在,直接返回,然后要在当前结点值前面加上左括号,然后判断,如果左子结点不存在,而右子结点存在的话,要在结果res后加上个空括号,然后分别对左右子结点调用递归函数,调用完之后要加上右括号,形成封闭的括号。由于最外面一层的括号不需要,所以我们再返回最终结果之前要去掉首尾的括号,参见代码如下:
解法一:
下面来看一种不用额外函数的递归写法,这种做法是一开始调用递归函数求出左右子结点的返回字符串,如果左右结果串均为空,则直接返回当前结点值;如果左子结果串为空,那么返回当前结果res,加上一个空括号,再加上放在括号中的右子结果串;如果右子结果串为空,那么发返回当前结果res,加上放在括号中的左子结果串;如果左右子结果串都存在,那么返回当前结果,加上分别放在括号中的左右子结果串,参见代码如下:
解法二:
下面这种解法更加简洁,由热心网友edyyy提供,思路和上面解法相同,参见代码如下:
解法三:
类似题目:
Construct Binary Tree from String
参考资料:
https://discuss.leetcode.com/topic/91308/java-solution-tree-traversal
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: