Given a binary tree, return the vertical order traversal of its nodes’ values. (ie, from top to bottom, column by column).
If two nodes are in the same row and column, the order should be from left to right.
Examples:
return its vertical order traversal as:
Given binary tree [3,9,8,4,0,1,7],
return its vertical order traversal as:
Given binary tree [3,9,8,4,0,1,7,null,null,null,2,5] (0’s right child is 2 and 1’s left child is 5),
return its vertical order traversal as:
解法1:
一种BFS的增强用法
在每次push一个node到一个queue的同时,维护另外一个queue,记录相对应的node的信息
用一个hashmap记录每一个col对应的答案。
然后min,max记录col的范围,之后把map里的数字再按顺序读取就可以了
C++
Java