Easy To Understand || C++ || Python || Java
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThe code iterates through the colors string and checks for consecutive oc
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe code iterates through the colors string and checks for consecutive occurrences of \'A\' and \'B\'.\nIt maintains two counters, \'count\' for consecutive \'A\'s and \'count1\' for consecutive \'B\'s.\nWhenever three \'A\'s or three \'B\'s occur consecutively, it increments the respective counter.\nFinally, it returns \'true\' if \'count\' is greater than \'count1\', indicating that \'A\' has more consecutive occurrences than \'B\', otherwise it returns \'false\'.\n# Complexity\n- Time complexity:\nTime complexity: O(N), where N is the length of the input string colors.\n\n- Space complexity:\nSpace complexity: O(1), as it uses a constant amount of extra space to store the counters count and count1.\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int count=0,count1=0;\n        for(int i=1; i<colors.length()-1;i++)\n        {\n            if(colors[i] ==\'A\' && colors[i-1]==\'A\' && colors[i+1]==\'A\')\n            {\n                count++;\n            }\n            else if(colors[i]==\'B\' && colors[i-1]==\'B\' && colors[i+1]==\'B\')\n            {\n                count1++;\n            }\n        }\n        return count>count1;\n    }\n};\n```\n```python []\nclass Solution:\n    def winnerOfGame(self, colors: str) -> bool:\n        count = 0\n        count1 = 0\n        for i in range(1, len(colors) - 1):\n            if colors[i] == \'A\' and colors[i - 1] == \'A\' and colors[i + 1] == \'A\':\n                count += 1\n            elif colors[i] == \'B\' and colors[i - 1] == \'B\' and colors[i + 1] == \'B\':\n                count1 += 1\n        return count > count1\n\n```\n```Java []\npublic class Solution {\n    public boolean winnerOfGame(String colors) {\n        int count = 0;\n        int count1 = 0;\n        for (int i = 1; i < colors.length() - 1; i++) {\n            if (colors.charAt(i) == \'A\' && colors.charAt(i - 1) == \'A\' && colors.charAt(i + 1) == \'A\') {\n                count++;\n            } else if (colors.charAt(i) == \'B\' && colors.charAt(i - 1) == \'B\' && colors.charAt(i + 1) == \'B\') {\n                count1++;\n            }\n        }\n        return count > count1;\n    }\n}\n\n```\n\n\n\n\n\n
['C++']