剑指offer数学62.圆圈中最后剩下的数字

Posted trevo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了剑指offer数学62.圆圈中最后剩下的数字相关的知识,希望对你有一定的参考价值。

题目链接:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/

数学

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

以上是关于剑指offer数学62.圆圈中最后剩下的数字的主要内容,如果未能解决你的问题,请参考以下文章