6.8 Tree

  1. Employee Importance

最简单的DFS, 设置了一个公司上下级关系的背景而已,

input: 一个employee对象的list, 一个employee id,
output: total important value of the employee and his subordinate of employee

问题: 如何在list当中找到这个unique id的employee, 使用一个for loop ?

people不是数组,是一个个Employee类,不使用List的get() 方法

使用HashMap 来提高运行效率:
Map当中存什么? employee 和 id 一一对应的关系, 便于后期的查找
HashMap的创建 ``

Map<Integer, Employee> map = new HashMap<>();
for (Employee e : employees) {
    map.push(e.id, e);
}

再定义一个辅助的helper()function
private int helper(Map<Integer, Employee> map, int id) {..}

类名应当开头大写!!!
遍历的对象搞错了。

  1. Max Area of Island
    一个常量记录最后的结果,
    如何判断岛屿是同一个岛屿,

  2. Number of island

有一种BFS 与 DFS相结合的感觉,DFS来完全遍历得到一个完整的岛屿,BFS来保证不遗漏

posted @ 2018-06-09 23:44  AugusKong  阅读(123)  评论(0编辑  收藏  举报