转载原文链接
class Solution {
public:
int findTheWinner(int n, int k) {
int pos = 0; //我们这里使用0下标来执行迭代
for (int i = 2; i < n + 1; ++i) { //i 为游戏的人数
pos = (pos + k) % i;
}
return pos + 1; //题意要求,如果是下标1开始,这里+1,否则直接返回pos
}
};
作者:fuxuemingzhu
链接:https://leetcode-cn.com/problems/find-the-winner-of-the-circular-game/solution/by-fuxuemingzhu-laof/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。