
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.
In a binary tree, the root node is at depth
0
, and children of each depthk
node are at depthk+1
.Two nodes of a binary tree are cousins if they have the same depth, but have different parents.
We are given the
root
of a binary tree with unique values, and the valuesx
andy
of two different nodes in the tree.Return
true
if and only if the nodes corresponding to the valuesx
andy
are cousins.Example 1:

Example 2:

Example 3:
Constraints:
2
and100
.1
to100
.这道题定义了一种二叉树数的表兄弟结点,就是不属于同一个父结点,但是深度相同,现在给了两个结点值,问它们代表的结点是否是表兄弟结点。由于表兄弟结点一定是属于同一层的,所以可以使用二叉树的层序遍历,就像之前那道 Binary Tree Level Order Traversal 一样。这里额外需要两个布尔型变量 isX,isY 来记录x和y是否已经遍历到了。由于是层序遍历,所以 while 中需要有个 for 循环,在循环中,取出队首结点,然后看结点值是否等于x或y,是的话标记布尔变量。然后检查当前结点的左右子结点是否分别是x和y,是的话直接返回 false。否则将左右子结点排入队列之中,若存在的话。当前层遍历完了之后,检查 isX 和 isY 的值,若同时为 true,表示存在表兄弟结点,返回 true。若只有一个为 true 的话,说明二者不在同一层,直接返回 false,参见代码如下:
解法一:
当然我们也可以用递归的方法来做,由于不能同时处理同一层的结点,就需要两个变量 depthX 和 depthY 来记录结点x和y的深度,同时再用个布尔变量 sameParent 来记录这两个结点是否有相同的父结点。在递归函数中,若当前结点 node 为空,直接返回。若当前结点值是x,则 depthX 赋值为当前深度 cur,同理,若当前结点值是y,则 depthY 赋值为当前深度 cur。然后检查当前结点的左右子结点是否分别是x和y,是的话 sameParent 标记为 true,最后分别对左右子结点调用递归即可,参见代码如下:
解法二:
接下来这种方法是博主在 Contest 时想出来的,思路比较简单粗暴,就是建立每个结点和其深度跟父结点组成的 pair 对儿之间的映射,然后就可以直接用x和y去获得其深度和父结点进行比较即可,参见代码如下:
解法三:
Github 同步地址:
#993
类似题目:
Binary Tree Level Order Traversal
参考资料:
https://leetcode.com/problems/cousins-in-binary-tree/
https://leetcode.com/problems/cousins-in-binary-tree/discuss/238536/My-Easy-Recursive-C%2B%2B-Solution
https://leetcode.com/problems/cousins-in-binary-tree/discuss/239376/Java-BFS-time-and-space-beat-100
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: