Skip to content

Commit 03cd2e6

Browse files
authored
Create 1758-minimum-changes-to-make-alternating-binary-string.kt
1 parent ca4d5f0 commit 03cd2e6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
fun minOperations(s: String): Int {
3+
var count = 0
4+
5+
for ((i, c) in s.withIndex()) {
6+
if (i % 2 == 0)
7+
count += if (c == '0') 1 else 0
8+
else
9+
count += if (c == '1') 1 else 0
10+
}
11+
12+
return minOf(count, s.length - count)
13+
}
14+
}

0 commit comments

Comments
 (0)