✔ Python3 Solution
Complexity\n- Time complexity: O(n)\n- Space complexity: O(1)\n\n# Code\n\nclass Solution:\n    def minFlips(self, s):\n        n = len(s)\n        e, o = (n + 
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution:\n    def minFlips(self, s):\n        n = len(s)\n        e, o = (n + 1) // 2, n // 2\n        x = s[::2].count(\'1\') - s[1::2].count(\'1\')\n        ans = min(e - x, o + x)\n        if n&1 == 0: return ans\n        for i in s:\n            x = 2 * int(i) - x\n            ans = min(ans, e - x, o + x)\n        return ans\n```
['Python3']