Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-06-03 15:42:02
https://leetcode.com/problems/time-needed-to-inform-all-employees/description/
1376. Time Needed to Inform All Employees
给你数字 n 表示员工数量,headID 表示老板,manager[] 表示每个人他的上司是谁,
informTime[] 表示通知下属要花多久(没下属的话是0),今天老板有话要通知全公司
,他会通知地位最高的主管并让主管交接给他的下级主管,题目保证所有员工都会被
通知,请问全公司都收到消息最快要花多久?
Example 1:
Input: n = 1, headID = 0, manager = [-1], informTime = [0]
Output: 0
Explanation: The head of the company is the only employee in the company.
Example 2:
Input: n = 6, headID = 2, manager = [2,2,-1,2,2,2], informTime = [0,0,1,0,0,0]
https://assets.leetcode.com/uploads/2020/02/27/graph.png
Output: 1
Explanation: The head of the company with id = 2 is the direct manager of all
the employees in the company and needs 1 minute to inform them all.
The tree structure of the employees in the company is shown.
思路:
1.所有员工都要被通知到,可以把关系转变成一颗树,老板当作是子节点并记录
每个人的下属有哪些。
2.对所有下属做DFS,并比较所有底层员工收到消息时花了多久,取最长的时间。
Java Code:
作者: pandix (面包屌)   2023-06-03 15:57:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com