找到连续赢K场比赛的第一位玩家 📝发布:2024-10-25 题目描述1 代码 c++javapython #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; } 链接 找到连续赢K场比赛的第一位玩家https://leetcode.cn/problems/find-the-first-player-to-win-k-games-in-a-row/description/ ↩︎