Skip to content

Instantly share code, notes, and snippets.

@humpydonkey
Created April 6, 2021 19:29
Show Gist options
  • Save humpydonkey/592b266fe5af5d15cd92b82712162de2 to your computer and use it in GitHub Desktop.
Save humpydonkey/592b266fe5af5d15cd92b82712162de2 to your computer and use it in GitHub Desktop.
"""
# Definition for Employee.
class Employee:
def __init__(self, id: int, importance: int, subordinates: List[int]):
self.id = id
self.importance = importance
self.subordinates = subordinates
"""
class Solution:
def getImportance(self, employees: List['Employee'], id: int) -> int:
id_map = { e.id: e for e in employees }
def aggregate(id: int) -> int:
e = id_map[id]
return e.importance + sum(aggregate(sub_id) for sub_id in e.subordinates)
return aggregate(id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment