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
相关推荐
郝学胜-神的一滴4 分钟前
Python 抽象基类深度解析:从简易模拟到 abc 模块的优雅实践
开发语言·python·pycharm
Python伍六七16 分钟前
给予Python开发的【16款高效办公自动化工具合集】,告别低效加班!
开发语言·python·自动化
懷淰メ18 分钟前
【AI加持】基于PyQt+YOLO+DeepSeek的舌苔情况检测系统(详细介绍)
python·yolo·目标检测·计算机视觉·pyqt·舌苔
云渊未归0618 分钟前
Python获取GitCode项目信息
python·数据分析·开源·网络爬虫·gitcode
qingyulee33 分钟前
python redis
开发语言·redis·python
互联网时光机1 小时前
我用 UniApp + 腾讯云 IAI 做了一个“明星脸比对“小程序,零后台延迟
经验分享·python·人脸识别
l1t1 小时前
DeepSeek总结的Python 3.14.5 发布候选版本
开发语言·python
Cyber4K2 小时前
【Python专项】进阶语法-日志分类与分析(2)
开发语言·前端·python
lbb 小魔仙2 小时前
Python + LangChain 环境搭建完全指南:从零构建本地 RAG 知识库(附 Ollama 本地模型集成)
开发语言·python·langchain
风落无尘2 小时前
Python 包发布全流程:从项目结构到 PyPI 上线,以及我踩过的那些坑
开发语言·python·pip