首页 > 试题广场 >

Department list to tree

[编程题]Department list to tree
  • 热度指数:1112 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
Convert the department list to preorder traversal of the name of department tree
示例1

输入

[["d1", "d0", "IT"], ["d2", "d0", "RD"], ["d0", "", "The Company"], ["d3", "d0", "HR"]]

输出

["The Company","HR","IT","RD"]

说明

On each level of the department tree, departments are listed in alphabetical order of the name
头像 ShaunWong
发表于 2021-06-01 00:55:22
列表每一个条目第一个字符串是当前部门id,第二个字符串是父节点(父部门)id,第三个字符串是部门名称。主要思想:1.建立父节点id到其所有子节点的映射(子节点集合set有序,而且是字典序。 2.建立部门名称到部门id的映射。 3.找到根节点。 4.从根 展开全文