0
点赞
收藏
分享

微信扫一扫

每日一题Day<2022/2/15>

佳简诚锄 2022-02-15 阅读 39
javaleetcode

①,题目:

 力扣690. 员工的重要性icon-default.png?t=M0H8https://leetcode-cn.com/problems/employee-importance/

②,代码:

class Solution {
    public int allImportance=0;
    public int getImportance(List<Employee> employees, int id) {
    for (Employee e:employees){
        //1,找到当前id的Employee
        if (e.id==id){
            allImportance+=e.importance;
            //3,终止递归
            // 存在一次递归结束过程的情况,所以返回结果allImportance。
            if (e.subordinates.size()==0)
                return allImportance;
            //2,找到当前id的下属
            for (int i:e.subordinates) {
                getImportance(employees,i);
            }
        }
    }
    return allImportance;
    }
}

③,运行:

举报

相关推荐

每日一题Day<2022/1/20>

每日一题15

每日一题day01

寒假-每日一题-day 08

每日一题day1

AcWing 寒假每日一题2022

0 条评论