Skip to content

Commit

Permalink
Create 1422-maximum-score-after-splitting-a-string.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
a93a authored Dec 22, 2023
1 parent e147dcd commit 5e4ae49
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions kotlin/1422-maximum-score-after-splitting-a-string.kt
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 5e4ae49

Please sign in to comment.