Created
April 6, 2021 19:29
-
-
Save humpydonkey/592b266fe5af5d15cd92b82712162de2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
# 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