🔥💥 Easy Simple C++ Code With O(n) Time Complexity & O(1) Space Complexity 💥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to determine the winner of a game based on a sequence of colors denoted by 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to determine the winner of a game based on a sequence of colors denoted by \'A\' and \'B\'. We aim to count the occurrences of \'A\' and \'B\' sequences of length 3 or more. The player with the most such occurrences is declared the winner.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize counters for player \'A\' (`cnt_a`) and player \'B\' (`cnt_b`) to keep track of valid sequences for each player.\n2. Traverse the input colors string character by character.\n3. For each character:\n    - If it\'s `\'A\'`, count the length of the \'A\' sequence and update cnt_a accordingly if the `length is 3 or more`.    \n    -  If it\'s `\'B\'`, count the length of the \'B\' sequence and update cnt_b accordingly if the `length is 3 or more`.\n4. Compare the counts (`cnt_a` and `cnt_b`) to determine the winner of the game.\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n            int cnt_a = 0;\n    int cnt_b = 0;\n    int n=colors.size();\n    int j(0);\n    while(j<n){\n        if(colors[j]==\'A\'){\n            int cnt =0;\n            while(colors[j]==\'A\' and j<n){\n                cnt++;\n                j++;\n            }\n            if(cnt>=3) cnt_a += cnt-2;\n        }\n        if(colors[j]==\'B\'){\n            int cnt =0;\n            while(colors[j]==\'B\' and j<n){\n                cnt++;\n                j++;\n            }\n            if(cnt>=3) cnt_b += cnt-2;\n        }\n    }\n\n    return cnt_a > cnt_b;\n    }\n};\n```
['String', 'Greedy', 'Game Theory', 'C++']