Python | Leetcode Python题解之第390题消除游戏
题目:
题解:
class Solution:def lastRemaining(self, n: int) -> int:a1 = 1k, cnt, step = 0, n, 1while cnt > 1:if k % 2 == 0: # 正向a1 += stepelse: # 反向if cnt % 2:a1 += stepk += 1cnt >>= 1step <<= 1return a1
题目:
题解:
class Solution:def lastRemaining(self, n: int) -> int:a1 = 1k, cnt, step = 0, n, 1while cnt > 1:if k % 2 == 0: # 正向a1 += stepelse: # 反向if cnt % 2:a1 += stepk += 1cnt >>= 1step <<= 1return a1