
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, return the vertical order traversal of its nodes values.
For each node at position
(X, Y)
, its left and right children respectively will be at positions(X-1, Y-1)
and(X+1, Y-1)
.Running a vertical line from
X = -infinity
toX = +infinity
, whenever the vertical line touches some nodes, we report the values of the nodes in order from top to bottom (decreasingY
coordinates).If two nodes have the same position, then the value of the node that is reported first is the value that is smaller.
Return an list of non-empty reports in order of
X
coordinate. Every report will have a list of values of nodes.Example 1:
Example 2:
Note:
1000
nodes.0
and1000
.这道题是让给二叉树进行竖直遍历,怎么隐约感觉以前做过这道题,结果去查了一下,果然有 Binary Tree Vertical Order Traversal。怎么把标题顺序调换一下就是一道新题,Excuse me???结果仔细研究一下,两道题还真有些不同,不同点就是在于这道题对于同一列中的结点值的顺序还有要求,此处应有尼克杨问号脸??就是说默认是按y值从大到小排列的,但如果y值相同,则按结点值从小到大排,我也是给跪了。好吧,你赢了,将就着做吧。这道题之所以比之前的那道类似的题目难,原因是把y值也扯进来了,那么数据结构中也要给y值留个位置,大体思路其实还是一样的。这里要用到比较复杂的数据结构,同时用到两个 TreeMap 嵌在一块。用 TreeMap 的好处就是可以自动排序了,外层的映射 key 是x值,这样保证了x值是从小到大的,符合题目中要求的顺序。内层的映射是y值和一个放结点值的 TreeSet,之所以使用 TreeSet 也是利用其可以自动排序的特点,因为当y值相同时,需要结点值从小到大排列。同理,在队列 queue 中也要把y值包含进去,这里可以用一个 pair 对儿,分别是结点和坐标值,初始时把根结点,还有其坐标放入队列开始遍历吧。遍历的过程其实并不难,就是取出队首结点,取出坐标,更新 TreeMap 中的映射,然后将存在的左右子结点加入队列中继续遍历。这里细心的读者会发现,为啥左右子结点的坐标的y值都是加1,而题目中明明写的减1啊?这是因为 TreeMap 是从小到大的默认顺序,而题目中要求的y值是从上到下递减,这样就是从大到小的顺序了,为了方便起见,改成加1,就可以得到题目中要求的顺序了,算是个小 trick 吧。当遍历结束后,所有的数据都存在了 TreeMap 中,只要遍历 TreeMap,并按顺序取出每列的结点值,组成数组放入结果 res 中即可,参见代码如下:
解法一:
接下来是递归的写法,基本解题思路没有太大的区别,可以参见上面的讲解来理解,参见代码如下:
解法二:
Github 同步地址:
#987
类似题目:
Binary Tree Vertical Order Traversal
参考资料:
https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/
https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/discuss/260502/C%2B%2B-BFSDFS
https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/discuss/231140/Add-clarification-for-the-output-order
https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/discuss/231125/Java-HashMap-and-TreeMap-and-PriorityQueue-Solution
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: