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
相关推荐
用户9385156350720 分钟前
Text2SQL 实战:用 DeepSeek 大模型实现自然语言查询 SQLite 数据库
python·sqlite
2601_9620996835 分钟前
Python环境下中文分词实现与应用探索
python·自然语言处理·中文分词·jieba·开源社区
en.en..36 分钟前
C语言核心解析:#define与typedef本质区别
开发语言·c++·算法
2601_9669496543 分钟前
批量获取多只股票五档盘口的极简方案:QuantDash Python SDK 实战指南
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
用户0190275816143 分钟前
如何用 Python 监控 A 股涨停跌停与封板/炸板?
python
Lyra_Infra1 小时前
云效主机部署场景下 Python 服务生命周期问题复盘
后端·python
刀鋒偏冷1 小时前
CentOS 7 配置 Python 3.12.4 + RTX 4090 深度学习环境全记录
python·深度学习·centos
DreamLife☼1 小时前
Agent开发环境搭建完全指南
python·docker·typescript·node·工业知识点
李可以量化2 小时前
miniqmt 行情的备选方案 ---tdxrs(下)
python
点心的游戏开发世界2 小时前
GDScript 入门笔记:目录
开发语言·笔记·游戏引擎·godot