Skip to content

Commit 5e4ae49

Browse files
authored
Create 1422-maximum-score-after-splitting-a-string.kt
1 parent e147dcd commit 5e4ae49

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
fun maxScore(s: String): Int {
3+
var zero = 0
4+
var one = s.count{ it == '1'}
5+
var res = 0
6+
7+
for (i in 0 until s.lastIndex) {
8+
if (s[i] == '0')
9+
zero++
10+
else
11+
one--
12+
res = maxOf(res, zero + one)
13+
}
14+
15+
return res
16+
}
17+
}

0 commit comments

Comments
 (0)