1884. Minimum Changes To Make Alternating Binary String
My accepted Python solution to LeetCode problem 1884, Minimum Changes To Make Alternating Binary String, running in 11ms.
- Difficulty: Easy
- Python
- Runtime 11ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 11ms, memory 17.5MB, accepted 2025-12-31.
class Solution:
def minOperations(self, s: str) -> int:
count1 = 0
for i, c in enumerate(s):
if c != str(i % 2):
count1 += 1
return min(count1, len(s) - count1)