技术栈

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. 最长特殊序列 Ⅰ
相关推荐
chushiyunen
4 分钟前
python中的内置属性 todo
开发语言·javascript·python
2301_79380469
7 分钟前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
Hommy88
15 分钟前
【开源剪映小助手】IPC 通信机制
python·开源·aigc·剪映小助手
Zaly.
36 分钟前
【Python刷题】LeetCode 1727 重新排列后的最大子矩阵
算法·leetcode·矩阵
Zhansiqi
1 小时前
dayy43
pytorch·python·深度学习
紫丁香
1 小时前
pytest_自动化测试3
开发语言·python·功能测试·单元测试·集成测试·pytest
杰杰798
2 小时前
Python面向对象——类的魔法方法
开发语言·python
chushiyunen
2 小时前
python中的魔术方法(双下划线)
前端·javascript·python
深蓝轨迹
2 小时前
@Autowired与@Resource:Spring依赖注入注解核心差异剖析
java·python·spring·注解
人工智能AI技术
2 小时前
Python 3.14.3更新!内存优化与安全补丁实战应用
python
热门推荐
01GitHub 镜像站点02Qwen3.5 开源全解析:从 0.8B 到 397B,代际升级 + 全场景选型指南03小黑课堂计算机二级WPSoffice题库软件下载安装教程(2026年3月最新版)04班级宠物园部署指南05围棋-html版本06OpenClaw 使用和管理 MCP 完全指南07UV安装并设置国内源08OpenClaw Control UI安全上下文访问配置09“wsl --install -d Ubuntu-22.04”下载慢,中国地区离线安装 Ubuntu 22.04 WSL方法(亲测2025年5月6日)10Labelme从安装到标注:零基础完整指南