Shortest One-Pass Solution | C++, Python, Java
Approach\n Describe your approach to solving the problem. \nWe can use a 2D integer array of size n x 11 so that we can keep track of how many times each player
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can use a 2D integer array of size n x 11 so that we can keep track of how many times each player chose each color. If the amount of times they\'ve chosen any specific color excedes their player number, we add it to `res`. To make sure we don\'t add any player twice we use a boolean array `seen` to mark players when they win. This way we only need to go throuch `pick` once.\n# Complexity\n- Time complexity: $$O(m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int winningPlayerCount(int n, vector<vector<int>>& pick) {\n        int players[10][11] = {}, res = 0;\n        bool seen[10] = {};\n        for (auto& p : pick){\n            if (++players[p[0]][p[1]] > p[0] && !seen[p[0]]){\n                res++;\n                seen[p[0]] = true;\n            }\n        }\n        return res;\n    }\n};\n```\n```python []\nclass Solution:\n    def winningPlayerCount(self, n: int, pick: List[List[int]]) -> int:\n        res = 0\n        seen = set()\n        players = [[0] * 11 for _ in range(n)]\n        for x, y in pick:\n            if players[x][y] == x and x not in seen:\n                res += 1\n                seen.add(x)\n            players[x][y] += 1\n        return res\n```\n```Java []\nclass Solution {\n    public int winningPlayerCount(int n, int[][] pick) {\n        int res = 0;\n        int[][] players = new int[n][11];\n        boolean[] seen = new boolean[n];\n        for (int[] p : pick){\n            if (++players[p[0]][p[1]] > p[0] && !seen[p[0]]){\n                res++;\n                seen[p[0]] = true;\n            }\n        }\n        return res;\n    }\n}\n```\n
['C', 'Simulation', 'Python', 'C++', 'Java', 'Python3']