Video Solution | Explanation With Drawings | In Depth | C++ | Java | Python 3
Intuition and approach discussed in detail in video solution\nhttps://youtu.be/Pkywd65nA6Q\n\n# Code\nC++\n\nclass Solution {\npublic:\n    bool winnerOfGame(st
# Intuition and approach discussed in detail in video solution\nhttps://youtu.be/Pkywd65nA6Q\n\n# Code\nC++\n```\nclass Solution {\npublic:\n    bool winnerOfGame(string colors) {\n        int threeA = 0;\n        int threeB = 0;\n        int sz = colors.size();\n        for(int indx = 1; indx < sz - 1; indx++){\n            if(colors[indx] == \'A\' && colors[indx+1] == \'A\' && colors[indx-1] == \'A\'){\n\n               threeA++;\n            }else if(colors[indx] == \'B\' && colors[indx+1] == \'B\' && colors[indx-1] == \'B\'){\n                threeB++;\n            }\n        }\n        return threeA > threeB;\n    }\n};\n```\nJava\n```\nclass Solution {\n    public boolean winnerOfGame(String clrs) {\n        int threeA = 0;\n        int threeB = 0;\n        int sz = clrs.length();\n        char colors[] = clrs.toCharArray();\n        for(int indx = 1; indx < sz - 1; indx++){\n            if(colors[indx] == \'A\' && colors[indx+1] == \'A\' && colors[indx-1] == \'A\'){\n\n               threeA++;\n            }else if(colors[indx] == \'B\' && colors[indx+1] == \'B\' && colors[indx-1] == \'B\'){\n                threeB++;\n            }\n        }\n        return threeA > threeB;\n    }\n}\n```\nPython 3\n```\nclass Solution:\n    def winnerOfGame(self, clrs: str) -> bool:\n        threeA = 0\n        threeB = 0\n        sz = len(clrs)\n        colors = list(clrs)\n        for indx in range(1, sz - 1):\n            if colors[indx] == \'A\' and colors[indx+1] == \'A\' and colors[indx-1] == \'A\':\n                threeA += 1\n            elif colors[indx] == \'B\' and colors[indx+1] == \'B\' and colors[indx-1] == \'B\':\n                threeB += 1\n        return threeA > threeB\n```
['C++', 'Java', 'Python3']