Skip to content

Commit a8caa4e

Browse files
committed
Improved 3458
1 parent 8be1f25 commit a8caa4e

File tree

2 files changed

+4
-6
lines changed
  • src/main/kotlin/g3401_3500
    • s3458_select_k_disjoint_special_substrings
    • s3459_length_of_longest_v_shaped_diagonal_segment

2 files changed

+4
-6
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package g3401_3500.s3458_select_k_disjoint_special_substrings
22

33
// #Medium #String #Hash_Table #Dynamic_Programming #Sorting #Greedy
4-
// #2025_02_18_Time_28_ms_(33.33%)_Space_39.48_MB_(66.67%)
4+
// #2025_02_18_Time_24_ms_(100.00%)_Space_39.71_MB_(50.00%)
55

66
class Solution {
77
fun maxSubstringLength(s: String, k: Int): Boolean {
8-
if (k == 0) {
9-
return true
10-
}
8+
if (k == 0) return true
119
val n = s.length
1210
val left = IntArray(26) { n }
1311
val right = IntArray(26) { -1 }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package g3401_3500.s3459_length_of_longest_v_shaped_diagonal_segment
22

33
// #Hard #Array #Dynamic_Programming #Matrix #Memoization
4-
// #2025_02_18_Time_289_ms_(_%)_Space_147.08_MB_(100.00%)
4+
// #2025_02_18_Time_287_ms_(_%)_Space_131.62_MB_(100.00%)
55

66
import kotlin.math.max
77

@@ -53,7 +53,7 @@ class Solution {
5353
if (k > 0) {
5454
val d2 = (d + 1) % 4
5555
val res2 = dp(i + ds[d2][0], j + ds[d2][1], nx[x], d2, 0) + 1
56-
res = max(res.toDouble(), res2.toDouble()).toInt()
56+
res = max(res, res2)
5757
}
5858
dp[i][j][d][k] = res
5959
return res

0 commit comments

Comments
 (0)