Skip to content

Commit 11a61ca

Browse files
authored
Create minimum-changes-to-make-alternating-binary-string.py
1 parent 396b2bf commit 11a61ca

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minOperations(self, s):
6+
"""
7+
:type s: str
8+
:rtype: int
9+
"""
10+
cnt = sum(int(c) == i%2 for i, c in enumerate(s))
11+
return min(cnt, len(s)-cnt)

0 commit comments

Comments
 (0)