leetcode690+典型树自上而下递归

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013554860/article/details/83445063

https://leetcode.com/problems/employee-importance/description/

/*
// Employee info
class Employee {
public:
    // It's the unique ID of each node.
    // unique id of this employee
    int id;
    // the importance value of this employee
    int importance;
    // the id of direct subordinates
    vector<int> subordinates;
};
*/
class Solution {
public:
    int getImportance(vector<Employee*> employees, int id) {
        int sum = 0;
        for(auto e:employees){
            if(e->id ==id){
                sum += e->importance;
                for(auto subid: e->subordinates){
                    int id = subid;
                    sum += getImportance(employees, id);
                }
            }
        }
        return sum;
    }
};

猜你喜欢

转载自blog.csdn.net/u013554860/article/details/83445063