技术栈

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

Mopes__2024-09-05 20:03

题目:

题解:

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
上一篇:C++ | Leetcode C++题解之第393题UFT-8编码验证
下一篇:LeetCode: 521. 最长特殊序列 Ⅰ
相关推荐
aqi00
20 小时前
15天学会AI应用开发(八)使用向量数据库实现RAG功能
人工智能·python·大模型·ai编程·ai应用
Csvn
21 小时前
`functools.lru_cache` —— 一行代码搞定缓存加速
后端·python
金銀銅鐵
2 天前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup11
2 天前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi00
2 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵
2 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf
2 天前
Agent 流程编排
后端·python·agent
copyer_xyf
2 天前
Agent RAG
后端·python·agent
热门推荐
012026年6月AI行业全景:从百模大战到Agent元年,这30天发生了什么?022026年6月AI大模型全景报告:GPT-5.6、Claude Opus 4.8、Gemini 3.5,中美AI三足鼎立谁主沉浮?03【AI】2026 年具身智能模型和世界模型总结04GitHub 镜像站点052026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf06AI科技热点日报 | 2026年6月1日07AI一周事件 · 2026-06-03 至 2026-06-0908Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析09上线仅72小时被强制下架:Claude Fable 5 的短命10Codex 下载安装指南:Windows 和 macOS 官方版下载