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
相关推荐
右耳朵猫AI几秒前
PHP技术周刊 2026年第20周
开发语言·php
我的xiaodoujiao7 分钟前
API 接口自动化测试详细图文教程学习系列23--结合Pytest框架使用4-前后置处理
python·学习·测试工具·pytest
weixin_BYSJ19877 分钟前
springboot旅游管理系统04470(附源码+开发文档+部署教程)
java·spring boot·python·算法·django·flask·旅游
方也_arkling12 分钟前
【Java-Day12】接口
java·开发语言
小小de风呀14 分钟前
de风——【从零开始学 C++】(十)vector的模拟实现
开发语言·c++
右耳朵猫AI21 分钟前
Rust技术周刊 2026年第20周
开发语言·后端·rust
kaico201830 分钟前
Python 在 Jenkins Pipeline 中的使用总结
开发语言·python·jenkins
流浪00131 分钟前
C++篇:深入理解 C++ 智能指针:从裸指针到 RAII 的蜕变
开发语言·c++
多彩电脑31 分钟前
在Kivy中制造可移动控件
python
丘山望岳32 分钟前
二叉搜索双壁——map和set
开发语言·数据结构·c++