Skip to content

Commit 57e09db

Browse files
authored
Create 1376-time-needed-to-inform-all-employees.kt
1 parent a9518fb commit 57e09db

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
fun numOfMinutes(n: Int, headID: Int, manager: IntArray, informTime: IntArray): Int {
3+
val adj = HashMap<Int, ArrayList<Int>>().apply {
4+
for (i in 0 until n)
5+
this[manager[i]] = getOrDefault(manager[i], ArrayList<Int>()).apply { add(i) }
6+
}
7+
8+
var res = 0
9+
with (LinkedList<Pair<Int, Int>>()){
10+
addLast(headID to 0)
11+
while(isNotEmpty()) {
12+
val (id, time) = removeFirst()
13+
res = maxOf(res, time)
14+
adj[id]?.forEach {
15+
addLast(it to (time + informTime[id]))
16+
}
17+
}
18+
}
19+
20+
return res
21+
}
22+
}

0 commit comments

Comments
 (0)