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
相关推荐
言乐617 分钟前
Python实现建造微服务商城后台
开发语言·python·算法·微服务·架构
fenglllle43 分钟前
chromadb emmbedding 向量检索
人工智能·python·embedding
wabs66644 分钟前
关于动态规划【力扣583.两个字符串的删除操作的思考】
算法·leetcode·动态规划
cui_ruicheng1 小时前
Python从入门到实战(六):非序列容器
开发语言·python
_Doubletful1 小时前
妙用位运算:解构汉明距离至100%(提供分析与多解)
c语言·算法·leetcode
凯瑟琳.奥古斯特1 小时前
力扣1013三等分解法与C++实现
开发语言·c++·算法·leetcode·职场和发展
飞猪~1 小时前
Langchain python版本 LLM 重要函数invoke,ainvoke,stream,astream,batch,abatch
python·langchain·batch
沙蒿同学2 小时前
当古诗词遇上 AI:从 38 万句诗词中取一个好名字
python·算法·架构
xxie1237942 小时前
Python装饰器与语法糖
开发语言·python
CClaris2 小时前
大模型量化从0到1(五):GPTQ 原理详解 + 从零量化一个真实大模型
人工智能·python·算法·机器学习