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
相关推荐
superman超哥2 分钟前
Rust 所有权转移在函数调用中的表现:编译期保证的零成本抽象
开发语言·后端·rust·函数调用·零成本抽象·rust所有权转移
xiaowu0802 分钟前
C# 把dll分别放在指定的文件夹的方法
开发语言·c#
耶夫斯计7 分钟前
【SQL_agent】基于LLM实现sql助理
数据库·python·sql·语言模型
vibag8 分钟前
RAG向量数据库
python·语言模型·langchain·大模型
kisshuan123968 分钟前
基于YOLO11改进的C3k2-AdditiveBlock实现命中检测与双重命中事件识别_1
python
mg66810 分钟前
0基础开发学习python工具_____用 Python + Pygame 打造绚丽烟花秀 轻松上手体验
开发语言·python·学习·pygame
nervermore99019 分钟前
2.6 测试
python
CodeOfCC21 分钟前
C++ 实现ffmpeg解析hls fmp4 EXT-X-DISCONTINUITY并支持定位
开发语言·c++·ffmpeg·音视频
ghie909021 分钟前
基于LSB匹配的隐写术MATLAB实现
开发语言·计算机视觉·matlab
Lhan.zzZ23 分钟前
Qt绘制残留问题排查与修复日志
开发语言·数据库·qt