其他分享
首页 > 其他分享> > 面试题:约瑟夫环

面试题:约瑟夫环

作者:互联网

为初始化每次删除node后的位置,将需要删除的node前的节点后移,从而完成位置初始化。

Python:

class Solution:
    def LastRemaining_Solution(self , n: int, m: int) -> int:
        # write code here
        res=[i for i in range(n)]
        while len(res)>1:
            for i in range(m-1):
                res.append(res.pop(0))
            res.pop(0)
        return res[0]

 

标签:node,面试题,int,res,Solution,pop,约瑟夫,range
来源: https://www.cnblogs.com/tiuyoaix/p/16221031.html