技术栈

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. 最长特殊序列 Ⅰ
相关推荐
用户835629078051
1 天前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon
1 天前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly
1 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程
1 天前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly
1 天前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
xlp666hub
1 天前
Leetcode 第三题:用C++解决最长连续序列
c++·leetcode
xlp666hub
1 天前
Leetcode第二题:用 C++ 解决字母异位词分组
c++·leetcode
明月_清风
1 天前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风
1 天前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
xlp666hub
2 天前
Leetcode第一题:用C++解决两数之和问题
c++·leetcode
热门推荐
01GitHub 镜像站点02OpenClaw 使用和管理 MCP 完全指南03本地部署 OpenClaw + DeepSeek-R1 完全指南04OpenClaw 连接飞书完整指南:插件安装、配置与踩坑记录05Window 10部署openclaw报错node.exe : npm error code 12806OpenClaw 接入 QQ Bot 完整实践指南07npm-error code 128问题解决方法08OpenClaw 飞书机器人不回复消息?3 小时踩坑总结09OpenClaw + 飞书(Feishu)环境搭建指南10OpenClaw-VSCode:在 VS Code 里玩转 OpenClaw,远程管理+SSH 双剑合璧