《剑指Offer》刷题笔记——面试题62. 圆圈中最后剩下的数字

难度:简单

一、题目描述:

在这里插入图片描述

二、解题分析:

class Solution:
    def lastRemaining(self, n: int, m: int) -> int:
        cur = 0
        nums = [i for i in range(n)]
        while True:
            inx = (cur + m%len(nums)-1)%len(nums)
            cur = inx
            del nums[inx]
            if len(nums)==1:
                break
        return nums[0]
发布了132 篇原创文章 · 获赞 154 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_34108714/article/details/104776099