Python | Parity Count | O(n)
Code\n\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        n = len(s)\n        even, odd = 0, 0\n        for i in range(n):\n            if i%2 an
# Code\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        n = len(s)\n        even, odd = 0, 0\n        for i in range(n):\n            if i%2 and s[i] == \'1\': odd += 1\n            if not i%2 and s[i] == \'1\': even += 1\n        if not n%2: \n            return min(odd + n//2 - even, even + n//2 - odd)\n        res = float(\'inf\')\n        for i in range(n):\n            if s[i] == \'1\':\n                even, odd = odd + 1, even - 1 \n                res = min(res, min(even + n//2 - odd, odd + n//2 + 1 - even))\n            else:\n                even, odd = odd, even\n                res = min(res, min(even + n//2 - odd, odd + n//2 + 1 - even))\n        return res\n```
['Python3']