Skip to content

Commit

Permalink
Improved task 3441
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev authored Feb 5, 2025
1 parent 2acb799 commit 5aaa0ce
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Solution {
return ""
}
val arr = caption.toCharArray()
val prefixCost = Array<IntArray?>(n + 1) { IntArray(26) }
val prefixCost = Array<IntArray>(n + 1) { IntArray(26) }
for (i in 0..<n) {
val orig = arr[i].code - 'a'.code
for (c in 0..25) {
prefixCost[i + 1]!![c] = prefixCost[i]!![c] + abs((orig - c))
prefixCost[i + 1][c] = prefixCost[i][c] + abs((orig - c))
}
}
val dp = IntArray(n + 1)
Expand All @@ -37,7 +37,7 @@ class Solution {
var bestLetter = 0
var bestCost: Int = INF
for (c in 0..25) {
val costBlock = prefixCost[i + l]!![c] - prefixCost[i]!![c]
val costBlock = prefixCost[i + l][c] - prefixCost[i][c]
if (costBlock < bestCost) {
bestCost = costBlock
bestLetter = c
Expand Down

0 comments on commit 5aaa0ce

Please sign in to comment.