Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57e09db

Browse files
authored
Create 1376-time-needed-to-inform-all-employees.kt
1 parenta9518fb commit57e09db

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+
classSolution {
2+
funnumOfMinutes(n:Int,headID:Int,manager:IntArray,informTime:IntArray):Int {
3+
val adj=HashMap<Int,ArrayList<Int>>().apply {
4+
for (iin0 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 to0)
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)

[8]ページ先頭

©2009-2025 Movatter.jp