[Java/C++/Python] One Pass, O(1) Space
Note this problem is almost same as problem\n3175. Find The First Player to win K Games in a Row\n\n\n# Intuition\nDon\'t need a queue or push the elements.\n\n
Note this problem is almost same as problem\n[3175. Find The First Player to win K Games in a Row](https://leetcode.com/problems/find-the-first-player-to-win-k-games-in-a-row/discuss/5280219/JavaC%2B%2BPython-One-Pass)\n<br>\n\n# **Intuition**\nDon\'t need a queue or push the elements.\n\nIf you don\'t find the winner after one pass,\nthe winner will be `max(A)`,\nbacause no one will beats him anymore.\n<br>\n\n# **Explanation**\n`cur` is the current winner, wich is the current biggest element.\n`win` is the number of games it has won.\nIf `max(A)` competes, it will be the winner.\n<br>\n\n# **Complexity**\nTime `O(N)`\nSpace `O(1)`\n<br>\n\n**Java:**\n```java\n    public int getWinner(int[] A, int k) {\n        int cur = A[0], win = 0;\n        for (int i = 1; i < A.length; ++i) {\n            if (A[i] > cur) {\n                cur = A[i];\n                win = 0;\n            }\n            if (++win == k) break;\n        }\n        return cur;\n    }\n```\n**C++:**\n```cpp\n    int getWinner(vector<int>& A, int k) {\n        int cur = A[0], win = 0;\n        for (int i = 1; i < A.size(); ++i) {\n            if (A[i] > cur) {\n                cur = A[i];\n                win = 0;\n            }\n            if (++win == k) break;\n        }\n        return cur;\n    }\n```\n\n**Python:**\n```py\n    def getWinner(self, A, k):\n        cur = A[0]\n        win = 0\n        for i in xrange(1, len(A)):\n            if A[i] > cur:\n                cur = A[i]\n                win = 0\n            win += 1\n            if (win == k): break\n        return cur\n```\n
[]