思路:
第一pop第i个。i=(0+m-1)%len(res)
第二次res变了,i从i后面一个开始计数,i=(i+m-1)%len(res)
最后剩一个拿出来
# -*- coding:utf-8 -*-
class Solution:
def LastRemaining_Solution(self, n, m):
# write code here
if n==1:
return n
if n==0:
return -1
res=range(n)
i=0
while len(res)>1:
i=(i+m-1)%len(res)
res.pop(i)
return res[0]