Depth-first Search-690. Employee Importance
You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id.
For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. They have importance value 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []]. Note that although employee 3 is also a subordinate of employee 1, the relationship is not direct.
Now given the employee information of a company, and an employee id, you need to return the total importance value of this employee and all his subordinates.
Example 1:
Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1
Output: 11
Explanation:
Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11.
Note:
- One employee has at most one direct leader and may have several subordinates.
 - The maximum number of employees won't exceed 2000.
 
class Solution
{
public int getImportance(List employees, int id)
{
int index = 0;
for(index = 0; index < employees.size(); index++)
{
if(employees.get(index).id == id)
break;
}
int result = employees.get(index).importance;
for(int i = 0; i < employees.get(index).subordinates.size(); i++)
{
result += getImportance(employees, employees.get(index).subordinates.get(i));
}
return result;
}
}
Depth-first Search-690. Employee Importance的更多相关文章
- (BFS) leetcode 690. Employee Importance
		
690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...
 - LN : leetcode 690  Employee Importance
		
lc 690 Employee Importance 690 Employee Importance You are given a data structure of employee inform ...
 - 【Leetcode_easy】690. Employee Importance
		
problem 690. Employee Importance 题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属. solution:DFS; /* // Employe ...
 - 690. Employee Importance - LeetCode
		
Question 690. Employee Importance Example 1: Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1 Outp ...
 - LeetCode - 690. Employee Importance
		
You are given a data structure of employee information, which includes the employee's unique id, his ...
 - LeetCode 690 Employee Importance 解题报告
		
题目要求 You are given a data structure of employee information, which includes the employee's unique id ...
 - [LeetCode&Python] Problem 690. Employee Importance
		
You are given a data structure of employee information, which includes the employee's unique id, his ...
 - 690. Employee Importance
		
好几种写法,这里贴几个出来 第一种:暴力解法,除去递归栈,空间复杂度O(1).时间复杂度略高 /* // Employee info class Employee { public: // It's ...
 - 690. Employee Importance员工权限重要性
		
[抄题]: You are given a data structure of employee information, which includes the employee's unique i ...
 - leetcode 690. Employee Importance——本质上就是tree的DFS和BFS
		
You are given a data structure of employee information, which includes the employee's unique id, his ...
 
随机推荐
- LayDate 时间选择插件的使用介绍 (低版本1.0好像是)
			
<span style="font-size:18px;"><!doctype html> <html> <head> <me ...
 - .net core web api swagger 配置笔记
			
参考网址: --配置步骤见如下链接https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swa ...
 - 80% UI 初学者走过的弯路,你走了几条?
			
关于UI 对于初学UI设计的人而言,可能对UI具体是做什么,或者自己是否能顺利转行胜任这样的岗位存在一定的顾虑,今天我们就来重点说说UI是做什么的,以及学UI到有哪些需要避免的弯路. 1.UI设计是做 ...
 - OSGi 系列(十四)之 Event Admin Service
			
OSGi 系列(十四)之 Event Admin Service OSGi 的 Event Admin 服务规范提供了开发者基于发布/订阅模型,通过事件机制实现 Bundle 间协作的标准通讯方式. ...
 - Activiti中23张表的含义
			
1.与流程定义相关的4张表: 2.与执行任务相关的5张表: 3.与流程变量相关的2张表
 - node.js初步总结
			
一:先上一段代码 process.argv.forEach(function (val, index, array) { console.log(index + ":" + ...
 - b2_trsd_EDSD_new
			
# -*- coding:utf-8 -*- import re ss="./data/" year = '17A' filename = ss+'EDSD%s.txt'%year ...
 - calltree+graphviz 绘出项目函数调用图
			
install calltree: download from http://linux.softpedia.com/progDownload/calltree-Download-971.html f ...
 - PGF基本图形对象
			
\documentclass{article} \usepackage[active ,tightpage ,xetex ]{ preview} \usepackage{tikz} \begin{do ...
 - VS2010与Qt5.1.0的集成
			
早就听说qt可以集成到VS中,就是一直没尝试过.一直在使用qt creator,也没觉得它有什么不好.可最近VS用多了,我发现一个qt creator中很不好的毛病,就是代码自动完成时,creator ...