[Java/Python 3] Count moves and compare.
Method 1:\n\n1. For each consecutive A or Bs, if its size is at least 3, then starting from the size of 3 count into moves of Alice or Bob, respectively.\n2. Co
**Method 1:**\n\n1. For each consecutive `A` or `B`s, if its size is at least `3`, then starting from the size of `3` count into moves of `Alice` or `Bob`, respectively.\n2. Compare to determine the winner.\n```java\n    public boolean winnerOfGame(String colors) {\n        char prev = \'C\';\n        int a = 0, b = 0;\n        for (int i = 0, cnt = 0; i < colors.length(); ++i) {\n            char cur = colors.charAt(i);\n            if (cur == prev) {\n                if (++cnt > 2) {\n                    if (cur == \'A\') {\n                        ++a;\n                    }else {\n                        ++b;\n                    }\n                }\n            }else {\n                cnt = 1;\n            }\n            prev = cur;\n        }\n        return a > b;\n    }\n```\n```python\n    def winnerOfGame(self, colors: str) -> bool:\n        a = b = cnt = 0\n        prev = \'C\' # dummy value.\n        for cur in colors:\n            if cur == prev:\n                cnt += 1\n                if cnt > 2:\n                    if cur == \'A\':\n                        a += 1\n                    else:\n                        b += 1\n            else:\n                cnt = 1\n            prev = cur\n        return a > b \n```\n\n----\n\n**Method 2: Count "AAA" or "BBB"** - credit to **@lokeshsenthilkumar**\n\n```java\n    public boolean winnerOfGame(String colors) {\n        int a = 0, b = 0;\n        for (int i = 2; i < colors.length(); ++i) {\n            if (colors.charAt(i - 2) == colors.charAt(i - 1) && colors.charAt(i - 1) == colors.charAt(i)) {\n                if (colors.charAt(i) == \'A\') {\n                    ++a;\n                }else {\n                    ++b;\n                }\n            }\n        }\n        return a > b;\n    }\n```\n\n```python\n    def winnerOfGame(self, colors: str) -> bool:\n        a = b = 0\n        for i in range(2, len(colors)):\n            if colors[i - 2] == colors[i - 1] == colors[i]:\n                if colors[i] == \'A\':\n                    a += 1\n                else:\n                    b += 1\n        return a > b\n```\n**Analysis:**\n\nTime: `O(n)`, space: `O(1)`, where `n = colors.length()`.
['Java', 'Python3']