Skip to content

Commit aca1a08

Browse files
committed
Fixed sonar
1 parent 9f2d404 commit aca1a08

File tree

2 files changed

+1
-12
lines changed
  • src/main/kotlin/g3701_3800

2 files changed

+1
-12
lines changed

src/main/kotlin/g3701_3800/s3713_longest_balanced_substring_i/Solution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Solution {
1414
var k = 0
1515
var m = 0
1616
for (j in i..<n) {
17-
val x = s.get(j).code - 'a'.code
17+
val x = s[j].code - 'a'.code
1818
if (++f[x] == 1) {
1919
++k
2020
}

src/main/kotlin/g3701_3800/s3714_longest_balanced_substring_ii/Solution.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,16 @@ class Solution {
7777
private fun findBalancedInRange(s: String, start: Int, end: Int, firstChar: Char, secondChar: Char): Int {
7878
val differenceMap: MutableMap<Int, Int> = HashMap<Int, Int>()
7979
differenceMap[0] = 0
80-
8180
var difference = 0
8281
var maxLength = 0
83-
8482
for (i in start..<end) {
8583
val currentChar = s[i]
86-
8784
if (currentChar == firstChar) {
8885
difference++
8986
} else if (currentChar == secondChar) {
9087
difference--
9188
}
92-
9389
val position = i - start + 1
94-
9590
if (differenceMap.containsKey(difference)) {
9691
maxLength = max(maxLength, position - differenceMap[difference]!!)
9792
} else {
@@ -109,27 +104,21 @@ class Solution {
109104
var maxLength = 0
110105
for (i in 0..<s.length) {
111106
val currentChar = s[i]
112-
113107
when (currentChar) {
114108
'a' -> {
115109
diff1++
116110
diff2++
117111
}
118-
119112
'b' -> diff1--
120113
'c' -> diff2--
121-
else -> {}
122114
}
123-
124115
val stateKey = encodeState(diff1, diff2)
125-
126116
if (stateMap.containsKey(stateKey)) {
127117
maxLength = max(maxLength, (i + 1) - stateMap[stateKey]!!)
128118
} else {
129119
stateMap[stateKey] = i + 1
130120
}
131121
}
132-
133122
return maxLength
134123
}
135124

0 commit comments

Comments
 (0)