Python | Leetcode Python题解之第390题消除游戏

题目:

题解:

python 复制代码
class Solution:
    def lastRemaining(self, n: int) -> int:
        a1 = 1
        k, cnt, step = 0, n, 1
        while cnt > 1:
            if k % 2 == 0:  # 正向
                a1 += step
            else:  # 反向
                if cnt % 2:
                    a1 += step
            k += 1
            cnt >>= 1
            step <<= 1
        return a1
相关推荐
nightunderblackcat21 分钟前
进阶向:人物关系三元组,解锁人物关系网络的钥匙
开发语言·python·开源·php
山顶风景独好22 分钟前
【Leetcode】随笔
数据结构·算法·leetcode
站大爷IP37 分钟前
Pandas与NumPy:Python数据处理的双剑合璧
python
站大爷IP1 小时前
Python枚举进化论:IntEnum与StrEnum的实战指南
python
甄超锋1 小时前
python sqlite3模块
jvm·数据库·python·测试工具·django·sqlite·flask
R-G-B2 小时前
OpenCV Python——Numpy基本操作(Numpy 矩阵操作、Numpy 矩阵的检索与赋值、Numpy 操作ROI)
python·opencv·numpy·numpy基本操作·numpy 矩阵操作·numpy 矩阵的检索与赋值·numpy 操作roi
细节处有神明2 小时前
Jupyter 中实现交互式图表:ipywidgets 从入门到部署
ide·python·jupyter
小小码农一只2 小时前
Python 爬虫实战:玩转 Playwright 跨浏览器自动化(Chromium/Firefox/WebKit 全支持)
爬虫·python·自动化
深盾安全4 小时前
Python脚本安全防护策略全解析(上)
python
杜子不疼.4 小时前
《Python学习之使用标准库:从入门到实战》
开发语言·python·学习