···

/*
// Employee info
class Employee {
// It's the unique id of each node;
// unique id of this employee
public int id;
// the importance value of this employee
public int importance;
// the id of direct subordinates
public List<Integer> subordinates;
};
*/

class Solution {

public int getImportance(List<Employee> employees, int id) { int sum = 0; for(Employee e:employees){ if(e.id == id){ sum += e.importance; List<Integer> sub = e.subordinates; if(sub.size()!=0){//不为空 for(Employee em:employees){ if(belong(sub,em.id)){ sum += getImportance(employees,em.id); } } return sum; } else{ return e.importance; } } } return sum; } public boolean belong(List<Integer> sub, int id){ for(Integer s:sub){ if(s==id) return true; } return false; }

}
···