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
相关推荐
yaoh.wang7 小时前
力扣(LeetCode) 13: 罗马数字转整数 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
小鸡吃米…8 小时前
Python PyQt6教程七-控件
数据库·python
1916zz9 小时前
Extreme programing 方利喆 _ 江贤晟
python
长安牧笛9 小时前
智能鞋柜—脚气终结者,内置温湿度传感器和紫外线灯,晚上回家,把鞋放进去,自动检测湿度,湿度超标就启动烘干+紫外线杀菌,第二天穿鞋干燥无异味。
python
weixin_457760009 小时前
PIL库将图片位深度是1、8、32统一转换为24的方法
python
Lucky高10 小时前
Pandas库入门
python·pandas
小鸡吃米…10 小时前
Python PyQt6教程三-菜单与工具栏
开发语言·python
sin_hielo10 小时前
leetcode 2110
数据结构·算法·leetcode
Jack电子实验室11 小时前
【杭电HDU】校园网(DeepL/Srun)自动登录教程
python·嵌入式硬件·计算机网络·自动化
木头左11 小时前
二值化近似计算在量化交易策略中降低遗忘门运算复杂度
python