binary tree vertical order traversal

🏠

credit

1 def verticalOrder(self, root):
2     cols = collections.defaultdict(list)
3     queue = [(root, 0)]
4     for node, i in queue:
5         if node:
6             cols[i].append(node.val)
7             queue += (node.left, i - 1), (node.right, i + 1)
8     return [cols[i] for i in sorted(cols)]