Employee Importance

此题比较简单,只是要注意雇员类里面的一些数据类型的问题

"""
# Employee info
class Employee(object):
    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(object):
    def getImportance(self, employees, id):
        """
        :type employees: Employee
        :type id: int
        :rtype: int
        """
        store = {x.id : (x.importance, x.subordinates) for x in employees}
        queue = collections.deque([id])
        checker = set([id])
        result = 0

        while queue:
            node = queue.pop()
            result += store[node][0]
            for sub in store[node][1]:
                if sub not in checker:
                    checker.add(sub)
                    queue.appendleft(sub)

        return result

results matching ""

    No results matching ""