Leetcode1006笨阶乘

思路:以4为一个分组分别进行处理

python 复制代码
class Solution:
    def clumsy(self, n: int) -> int:
        answer_dict = {0:0,1: 1, 2: 2, 3: 6, 4: 7}
        if n > 4:
            answer = n * (n - 1) // (n - 2) + n - 3
            n -= 4
        else:
            print(answer_dict[n])
            return answer_dict[n]
        print(answer)
        while n >=4:
            current_answer = n * (n - 1) // (n - 2) - n + 3
            answer -= current_answer
            n -= 4
            print(answer,n)
        answer-=answer_dict[n]
        print(answer)
        return answer
相关推荐
智能体与具身智能2 分钟前
TVA 本质内涵与核心特征(系列)
人工智能·python·智能体视觉
云雾J视界14 分钟前
SST:高频变压器设计实战:铁氧体 vs 纳米晶 vs 非晶,磁性材料怎么选
python·acdc·dab·sst
第一程序员26 分钟前
Rust trait 入门:把 AI 客户端抽象成可替换接口
python·rust·github
Ulyanov1 小时前
Python实现6-DOF刚体仿真器(下)——环境扰动与控制闭环
开发语言·python·算法·系统仿真·雷达电子对抗·导引头
分布式存储与RustFS1 小时前
RustFS Beta.10 性能解读:PUT 全面反超 MinIO,Rust 重写对象存储成了?
开发语言·后端·rust
小小的木头人1 小时前
Python 批量解析 Excel 经纬度,调用高德地图 API 获取中文地址
开发语言·python·excel
金銀銅鐵2 小时前
[Python] 为 Vole 机器语言实现图形化界面
python·程序员
小林ixn2 小时前
Python基础全梳理:从注释到函数,这些细节你都掌握了吗?
python·编程语言
nzz_1712142 小时前
PHP程序员转型AI岗位指南:核心技能、北京就业市场与转型路径分析
开发语言·人工智能·php
Risehuxyc2 小时前
C# 将doc转换为docx
开发语言·c#·xhtml