diff --git a/kotlin/1422-maximum-score-after-splitting-a-string.kt b/kotlin/1422-maximum-score-after-splitting-a-string.kt new file mode 100644 index 000000000..e41cd0013 --- /dev/null +++ b/kotlin/1422-maximum-score-after-splitting-a-string.kt @@ -0,0 +1,17 @@ +class Solution { + fun maxScore(s: String): Int { + var zero = 0 + var one = s.count{ it == '1'} + var res = 0 + + for (i in 0 until s.lastIndex) { + if (s[i] == '0') + zero++ + else + one-- + res = maxOf(res, zero + one) + } + + return res + } +}