约瑟夫环
class Solution { public: int LastRemaining_Solution(int n, int m) { if(n == 0) return -1; int idx = 0; int cnt = 2; while(cnt <= n){ idx = (idx + m) % cnt; cnt ++; } return idx; } };
约瑟夫环
class Solution { public: int LastRemaining_Solution(int n, int m) { if(n == 0) return -1; int idx = 0; int cnt = 2; while(cnt <= n){ idx = (idx + m) % cnt; cnt ++; } return idx; } };