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
相关推荐
你驴我6 小时前
WhatsApp 多账号消息路由中的去重与顺序保证实践
开发语言·php
aqi006 小时前
15天学会AI应用开发(十五)使用LangChain封装AI执行链
人工智能·python·大模型·ai编程·ai应用
wordpress资料库6 小时前
Next.js更适合移动开发 不适合web开发
开发语言·前端·javascript·next.js
wujf907 小时前
Go 内存泄漏排查完整教程 (pprof)
开发语言·golang·xcode
kisbad7 小时前
Day 012|Embedding 和向量数据库:知识库检索到底在检什么
数据库·python·embedding·agent
va学弟7 小时前
LeetCode 热题 100 题解(1):哈希
python·算法·leetcode·哈希算法
言乐67 小时前
Python实现基本搜索引擎
java·linux·开发语言·python·搜索引擎
FriendshipT7 小时前
Ultralytics:解读C3k2模块
人工智能·pytorch·python·深度学习·目标检测
啦啦啦_99997 小时前
Agent项目
python