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

Commit20dedab

Browse files
committed
Kotlin: 787. Cheapest Flights within K stops
1 parentfb55f39 commit20dedab

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
classSolution {
2+
funfindCheapestPrice(n:Int,flights:Array<IntArray>,src:Int,dst:Int,k:Int):Int {
3+
var cost=IntArray(n){Int.MAX_VALUE }
4+
cost[src]=0
5+
6+
for (iin0..k) {
7+
val temp= cost.clone()
8+
9+
for (flightin flights) {
10+
val (u, v, w)= flight
11+
12+
if (cost[u]!=Int.MAX_VALUE)
13+
temp[v]=Math.min(temp[v], cost[u]+ w)
14+
}
15+
16+
cost= temp
17+
}
18+
19+
returnif (cost[dst]==Int.MAX_VALUE)-1else cost[dst]
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp