题解 | #约瑟夫环#
孩子们的游戏(圆圈中最后剩下的数)
http://www.nowcoder.com/practice/f78a359491e64a50bce2d89cff857eb6
约瑟夫环
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; } };