[Python] for beginners
The idea is very simple and easy to follow.\n1. make s double size to check Type 1 rule\n2. create two templates, starting 1 first and 0 first\n3. compare with 
The idea is very simple and easy to follow.\n1. make s double size to check Type 1 rule\n2. create two templates, starting 1 first and 0 first\n3. compare with s and records the difference with two templates separately\n3. when for loop reach the end of s, check for the difference with substracting the first character\n4. return the minum number from the two differences\n\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        ls = len(s)\n        lnn = ls - 1\n        s += s # make s double size to check the type 1\n        ln = ls * 2\n        a = \'\'\n        b = \'\'\n        ca = \'1\'\n        cb = \'0\'\n        adif = 0\n        bdif = 0\n        out =  float(\'inf\')\n        for i in range(ln):\n            a += ca\n            b += cb\n            ca, cb = cb, ca\n            if a[i] != s[i]:\n                adif += 1\n            if b[i] != s[i]:\n                bdif += 1\n            if i >= lnn:\n                if i >= ls:\n                    if a[i-ls] != s[i-ls]:\n                        adif -= 1\n                    if b[i-ls] != s[i-ls]:\n                        bdif -= 1\n                out = min(out, adif, bdif)\n        \n        return out
[]