Skip to content

Commit 71069c7

Browse files
committed
Fixed sonar
1 parent 2508624 commit 71069c7

File tree

3 files changed

+7
-10
lines changed
  • src/main/kotlin/g3401_3500
    • s3407_substring_matching_pattern
    • s3410_maximize_subarray_sum_after_removing_all_occurrences_of_one_element
    • s3412_find_mirror_score_of_a_string

3 files changed

+7
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Solution {
2222
private fun `fun`(s: String, k: String): Int {
2323
val n = s.length
2424
val m = k.length
25-
var j = 0
25+
var j: Int
2626
for (i in 0..n - m) {
2727
j = 0
2828
while (j < m) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.math.min
88

99
class Solution {
1010
fun maxSubarraySum(nums: IntArray): Long {
11-
val prefixMap: MutableMap<Long?, Long?> = HashMap<Long?, Long?>()
11+
val prefixMap: MutableMap<Long, Long> = HashMap<Long, Long>()
1212
var result = nums[0].toLong()
1313
var prefixSum: Long = 0
1414
var minPrefix: Long = 0
@@ -28,7 +28,7 @@ class Solution {
2828
minPrefix = min(minPrefix, prefixMap[num.toLong()]!!)
2929
}
3030
prefixMap.put(0L, min(prefixMap[0L]!!, prefixSum))
31-
minPrefix = min(minPrefix.toDouble(), prefixMap.get(0L)!!.toDouble()).toLong()
31+
minPrefix = min(minPrefix, prefixMap[0L]!!)
3232
}
3333
return result
3434
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ package g3401_3500.s3412_find_mirror_score_of_a_string
55
class Solution {
66
fun calculateScore(s: String): Long {
77
val n = s.length
8-
val st: Array<ArrayList<Int?>?> = arrayOfNulls<ArrayList<Int?>>(26)
8+
val st: Array<ArrayList<Int>> = Array<ArrayList<Int>>(26) { ArrayList<Int>() }
99
var r: Long = 0
10-
for (i in 0..25) {
11-
st[i] = ArrayList<Int?>()
12-
}
1310
for (i in 0..<n) {
1411
val mc = 'z'.code - (s[i].code - 'a'.code)
1512
val p = mc - 'a'.code
16-
if (!st[p]!!.isEmpty()) {
17-
r += (i - st[p]!!.removeAt(st[p]!!.size - 1)!!).toLong()
13+
if (st[p].isNotEmpty()) {
14+
r += (i - st[p].removeAt(st[p].size - 1)).toLong()
1815
} else {
19-
st[s[i].code - 'a'.code]!!.add(i)
16+
st[s[i].code - 'a'.code].add(i)
2017
}
2118
}
2219
return r

0 commit comments

Comments
 (0)