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

Commit7fe92db

Browse files
authored
Create 2017-grid-game.kt
1 parent8e28396 commit7fe92db

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎kotlin/2017-grid-game.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
classSolution {
2+
fungridGame(grid:Array<IntArray>):Long {
3+
val n= grid[0].size
4+
val topPrefix=LongArray(n)
5+
val botPrefix=LongArray(n)
6+
7+
for (iin0 until n) {
8+
topPrefix[i]= grid[0][i].toLong()
9+
botPrefix[i]= grid[1][i].toLong()
10+
if (i>0 ) {
11+
topPrefix[i]+= topPrefix[i-1]
12+
botPrefix[i]+= botPrefix[i-1]
13+
}
14+
}
15+
16+
var res=Long.MAX_VALUE
17+
for (iin0 until n) {
18+
val rob2top= topPrefix[n-1]- topPrefix[i]
19+
val rob2bot=if (i>0) botPrefix[i-1]else0L
20+
21+
val rob2take= maxOf(
22+
rob2top,
23+
rob2bot
24+
)
25+
26+
res= minOf(
27+
res,
28+
rob2take
29+
)
30+
}
31+
32+
return res
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp