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
相关推荐
沐知全栈开发12 小时前
ionic 手势事件详解
开发语言
用户83562907805112 小时前
用 Python 轻松在 Excel 工作表中应用条件格式
后端·python
red1giant_star12 小时前
Python根据文件后缀统计文件大小、找出文件位置(仿Everything)
后端·python
雷欧力13 小时前
如何使用 Claude API?3 种接入方案实测,附完整代码(2026)
python·claude
lsx20240613 小时前
Bootstrap 按钮
开发语言
神仙别闹13 小时前
基于 Python 实现 BERT 的情感分析模型
开发语言·python·bert
禾叙_13 小时前
【langchain4j】结构化输出(六)
java·开发语言
NQBJT13 小时前
VS Code配置Python人工智能开发环境
开发语言·人工智能·vscode·python
浮游本尊13 小时前
一文讲透巡检链路:采集程序 → 上传数据包 → 后端解析入库 → 分析出报告
python
byoass13 小时前
智巢AI知识库深度解析:企业文档管理从大海捞针到精准狙击的进化之路
开发语言·网络·人工智能·安全·c#·云计算