You are viewing a single comment's thread. Return to all comments →
def topView(root): if not root: return hd_map = {} queue = deque([(root, 0)]) while queue: node, hd = queue.popleft() if hd not in hd_map: hd_map[hd] = node.info if node.left: queue.append((node.left, hd - 1)) if node.right: queue.append((node.right, hd + 1)) for hd in sorted(hd_map.keys()): print(hd_map[hd], end=" ")
Seems like cookies are disabled on this browser, please enable them to open this website
Tree : Top View
You are viewing a single comment's thread. Return to all comments →