java easy solution


  • 0
    S

    class Solution {
    int total = 0;
    public int getImportance(List<Employee> employees, int id) {
    int len = employees.size();
    Employee manager = new Employee();
    for (int i = 0; i < len; i++) {
    if (employees.get(i).id == id) {
    manager = employees.get(i);
    total += manager.importance;
    }
    }
    for (int i = 0; i < manager.subordinates.size(); i++) {
    getImportance(employees, manager.subordinates.get(i));
    }
    return total;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.