A python solution


  • 1
    Y
    class Solution(object):
        def getImportance(self, employees, id):
            """
            :type employees: Employee
            :type id: int
            :rtype: int
            """
            res = 0
            sons = []
            if not employees:
                return 0
            for employee in employees:
                if employee.id == id or employee.id in sons:
                    res += employee.importance
                    sons += employee.subordinates
            return res
    

  • 1
    C

    This is not correct, if your subordinates come after their leader in the loop.


Log in to reply
 

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