# -*- coding:utf-8 -*- class Node(): def __init__(self, x): self.val = x self.next = None class Solution: def LastRemaining_Solution(self, n, m): # write code here if not n: return -1 kids = [i for i in range(1, n)] root = Node(0) copy_root = root for i in kids: root.next = Node(i) root = root.next root.next = copy_root # 组建环形链表成功 if m == 1: return root.val for i in range(n - 1): for j in range(m - 1): root = root.next root.next = root.next.next return root.val