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

Commit0c821c3

Browse files
authored
Create 1335-minimum-difficulty-of-a-job-schedule.kt
1 parent11cb1e7 commit0c821c3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
classSolution {
2+
funminDifficulty(jobDifficulty:IntArray,d:Int):Int {
3+
if (jobDifficulty.size< d)return-1
4+
5+
val cache=HashMap<String,Int>()
6+
7+
fundfs(i:Int,d:Int,curMax:Int):Int {
8+
if (i== jobDifficulty.size) {
9+
returnif (d==0)0elseINFINITY
10+
}
11+
if (d==0)returnINFINITY
12+
cache["$i:$d:$curMax"]?.let {return it }
13+
14+
var max= maxOf(curMax, jobDifficulty[i])
15+
var res= minOf(
16+
dfs(i+1, d, max),
17+
max+ dfs(i+1, d-1,-1)
18+
)
19+
20+
cache["$i:$d:$max"]= res
21+
return res
22+
}
23+
24+
return dfs(0, d,-1)
25+
}
26+
27+
companionobject {
28+
constvalINFINITY=400000
29+
}
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp