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
相关推荐
wuyk55512 分钟前
Spider-第14讲-表单提交与CSRF
前端·爬虫·python·elasticsearch·csrf
汤姆宝库41 分钟前
RoPE旋转位置编码的实现与长上下文外推
python·深度学习·机器学习
用户019027581611 小时前
股票代码格式对照:各数据源代码转 AlphaFeed
python
__underline__2 小时前
冷门Python知识点005篇:list.sort( )的排序稳定性,是用0字节额外内存实现的
python·算法
贝壳6902 小时前
升到 9.13.12 我照着文档抄了两行,两次都炸了
python
VIP_CQCRE2 小时前
AI 音乐 API 上线后成本失控?用预算阈值、幂等任务和音频验收管住 Suno v6
python·api·suno·ai音乐·成本治理
2601_967980112 小时前
python list如何赋值
python·list·列表推导式·赋值·切片赋值
典学长编程3 小时前
LangGraph 快速入门:从 StateGraph 到 ReAct Agent
python·有向图·无向图·langgraph·react agent·stategraph
用户019027581616 小时前
AlphaFeed 查不到代码返回空?非法/缺后缀 symbol 的行为与处理
python
isfox6 小时前
Python 单元测试:别再用 print 调试了,写个测试一劳永逸
python