博文

目前显示的是 十二月, 2019的博文

Tree : Top View - HackerRank解题记录

图片
题目: You are given a pointer to the root of a binary tree. Print the top view of the binary tree. Top view means when you look the tree from the top the nodes, what you will see will be called the top view of the tree. See the example below. You only have to complete the function. For example :    1     \      2       \        5       /  \      3    6       \        4 Top View : 1 -> 2 -> 5 -> 6 Input Format You are given a function, void topView(node * root) { } Constraints 1 Nodes in the tree  500 Output Format Print the values on a single line separated by space. Sample Input    1     \      2       \        5       /  \      3    6       \     ...