✅ Easy and straightforward || One Loop 🔁, Indicators 🚦 || and animation 🎮"
Intuition\n\n\n\n# Approach\n Describe your approach to solving the problem. \n1. Initialize three variables: am and bm to keep track of the scores of players A
# Intuition\n![ezgif.com-video-to-gif (11).gif](https://assets.leetcode.com/users/images/f467437b-101c-49f5-a320-7e2d38f751e5_1696229474.0028176.gif)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Initialize three variables: **am** and **bm** to keep track of the scores of players A and B respectively, and **li** to keep track of the last index of a different color.\n\n1. Assign the first character of the colors string to the variable first. This character represents the color of the first ball in the game.\n\n1. Start a loop that iterates over the indices of the colors string, from 0 to colors.size() (inclusive).\n\n    1. Inside the loop, check if the current index i is equal to the size of the colors string or if the color at index i is different from the color at the first index (first). This condition checks if the current ball has a different color than the previous ones.\n\n    1. If the condition is true, calculate the score for the previous sequence of balls and update the corresponding player\'s score. The score is calculated by taking the maximum of 0 and the difference between the current index i, the last index li, and 2. This ensures that only sequences of at least 3 balls contribute to the score.\n\n    1. Update the last index li to the current index i, indicating the end of the previous sequence.\n\n    1. Update the first variable to the color of the new sequence of balls starting at index li.\n\n1. After the loop, compare the scores of players A and B. If player A\'s score (am) is greater than player B\'s score (bm), return true indicating that player A is the winner. Otherwise, return false indicating that player B is the winner.\n\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 am = 0, bm = 0, li = 0;\n        char first = colors[0];\n\n        for(int i = 0; i <= colors.size(); i++){\n            if(i == colors.size() || colors[i] != first){\n                if(first == \'A\') am += max(0, i - li - 2);\n                else bm += max(0, i - li - 2);\n                li = i;\n                first = colors[li];\n                \n            }\n        }\n        \n        return am > bm;\n    }\n};\n```\n\nhttps://youtu.be/vd8UenMAPAE
['C++']