Python Solution, Count '1' on odd and even positions
If s has even number of digits, we don\'t need to do the first operation at all. We simply count the number of ones on odd and even positions and derive the ans
If s has even number of digits, we don\'t need to do the first operation at all. We simply count the number of ones on odd and even positions and derive the answer. \n\nIf s has odd number of digits, we may consider the first operation. We need to refresh the number of ones on odd and even positions depending on the first digit of the string. \n\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        \n        n = len(s)\n        even, odd = 0, 0\n        for i in range(n): \n            if i % 2 == 1 and s[i] == \'1\': odd += 1\n            if i % 2 == 0 and s[i] == \'1\': even += 1\n        \n        print(n, even, odd)\n        if n % 2 == 0: \n            return min(even + n // 2 - odd, odd + n // 2 - even)\n        \n        if n % 2 == 1: \n            result = min(even + n // 2 - odd, odd + n // 2 + 1 - even)\n            for i in range(n): \n                if s[i] == \'1\': \n                    even, odd = odd + 1, even - 1\n                    result = min(result, min(even + n // 2 - odd, odd + n // 2 + 1 - even))\n                else: \n                    even, odd = odd, even\n                    result = min(result, min(even + n // 2 - odd, odd + n // 2 + 1 - even))\n            return result\n        \n            \n```
[]