Alternating Characters

  • + 0 comments
    def alternatingCharacters(s):
        s2 = re.sub(r'([AB])\1+', r'\1', s)
        return len(s) - len(s2)