剑指 Offer 62. 圆圈中最后剩下的数字(简单)

孜孜不倦fly / 2023-09-03 / 原文

题目:


class Solution {
public:
    int lastRemaining(int n, int m) {
        int pos = 0;
        for(int i=2;i<=n;i++){
            pos = (pos+m)%i;
        }
        return pos;
    }
};

作者:想吃火锅的木易
链接:https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/solutions/178427/huan-ge-jiao-du-ju-li-jie-jue-yue-se-fu-huan-by-as/
来源:力扣(LeetCode)