Sliding Windows approach | Easy CPP
Upvote is you like the approach \n# Code\n\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int n=colors.size();\n        if(n<=2) re
## Upvote is you like the approach \n# Code\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int n=colors.size();\n        if(n<=2) return false;\n        int i=0,j=2;\n        int cA=0,cB=0;\n        while(j<n)\n        {\n            if(colors[i]==\'A\' and colors[i+1]==\'A\' and colors[j]==\'A\')\n            {\n                cA++;\n            }\n            else if(colors[i]==\'B\' and colors[i+1]==\'B\' and colors[j]==\'B\')\n            {\n                cB++;\n            }\n            i++;\n            j++;\n\n        }\n        if(cA>cB) return true;\n        else return false;\n\n    }\n};\n```\n\n\n![image.png](https://assets.leetcode.com/users/images/06ea6a55-2aeb-495d-b1e5-74c4b14f52e3_1696224257.1960711.png)\n
['C++']