题目描述1

代码

c++
java
python
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int findWinningPlayer(vector<int>& skills, int k) {
        int n = skills.size();
		// index: 两个相邻元素比较最大数的索引.
        int index = 0;
        int count = 0;
        for (int j = 1; j < n;j++) {
            if (skills[index] < skills[j]) {
                index = j;
                count = 0;
            }
            if (++count == k) {
                return index;
            }
        }
        return index;
    }
};

int main() {
    vector<int> skills = {4,2,6,3,9};
    Solution solution;
    int result = solution.findWinningPlayer(skills, 2);
    cout << result << endl;
}

链接