LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 11ms, memory 17.5MB, accepted 2025-12-31.

python
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)

Source