8.6 第一次做,无法 AC
题目描述
原题链接:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/
解题思路
K 神题解:https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/solution/
8.6 心得
- 额,这题看题解有点难理解,现阶段先死记叭!
- x = (x + m) % i
- i 从 2 开始,因为 1 的结果就是 0,不要从 1 开始了!
class Solution {public int lastRemaining(int n, int m) {int x = 0;for(int i = 2; i <= n; i++) {x = (x + m) % i;}return x;}}
