Leetcode 690 Solution
This article provides solution to leetcode question 690 (employee-importance)
Access this page by simply typing in "lcs 690" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/employee-importance
Solution
"""
# Employee info
class Employee:
def __init__(self, id, importance, subordinates):
# It's the unique id of each node.
# unique id of this employee
self.id = id
# the importance value of this employee
self.importance = importance
# the id of direct subordinates
self.subordinates = subordinates
"""
class Solution:
def getImportance(self, employees, id):
"""
:type employees: Employee
:type id: int
:rtype: int
"""
employees = {
employee.id: employee
for employee in employees
}
def dfs(employee):
return employee.importance + sum([dfs(employees[report]) for report in employee.subordinates])
return dfs(employees[id])