Python解法
# -*- coding:utf-8 -*- #2020秋招vivo算法题二题源 class Solution: def LastRemaining_Solution(self, n, m): if n < 1: return -1 arr=list(range(n)) r=-1 l=0 while arr: k=(l+m-1)%n r=arr[k] arr.pop(k) n-=1 l=k return r
# -*- coding:utf-8 -*- #2020秋招vivo算法题二题源 class Solution: def LastRemaining_Solution(self, n, m): if n < 1: return -1 arr=list(range(n)) r=-1 l=0 while arr: k=(l+m-1)%n r=arr[k] arr.pop(k) n-=1 l=k return r
相关推荐