Skip to content

Commit 5aaa0ce

Browse files
authored
Improved task 3441
1 parent 2acb799 commit 5aaa0ce

File tree

1 file changed

+3
-3
lines changed
  • src/main/kotlin/g3401_3500/s3441_minimum_cost_good_caption

1 file changed

+3
-3
lines changed

src/main/kotlin/g3401_3500/s3441_minimum_cost_good_caption/Solution.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class Solution {
1313
return ""
1414
}
1515
val arr = caption.toCharArray()
16-
val prefixCost = Array<IntArray?>(n + 1) { IntArray(26) }
16+
val prefixCost = Array<IntArray>(n + 1) { IntArray(26) }
1717
for (i in 0..<n) {
1818
val orig = arr[i].code - 'a'.code
1919
for (c in 0..25) {
20-
prefixCost[i + 1]!![c] = prefixCost[i]!![c] + abs((orig - c))
20+
prefixCost[i + 1][c] = prefixCost[i][c] + abs((orig - c))
2121
}
2222
}
2323
val dp = IntArray(n + 1)
@@ -37,7 +37,7 @@ class Solution {
3737
var bestLetter = 0
3838
var bestCost: Int = INF
3939
for (c in 0..25) {
40-
val costBlock = prefixCost[i + l]!![c] - prefixCost[i]!![c]
40+
val costBlock = prefixCost[i + l][c] - prefixCost[i][c]
4141
if (costBlock < bestCost) {
4242
bestCost = costBlock
4343
bestLetter = c

0 commit comments

Comments
 (0)