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
相关推荐
铅笔侠_小龙虾17 分钟前
Rust 学习(4)-函数与注释
开发语言·学习·rust
tiana_31 分钟前
写了个零依赖的 Go 版本管理器,curl | bash 完事
开发语言·golang·bash
嘘嘘出差40 分钟前
Python 爬虫入门实战:爬取豆瓣电影 Top 250
开发语言·爬虫·python
爱写代码的倒霉蛋1 小时前
实现协程的三种方式
开发语言·python
崖边看雾1 小时前
记录Python学习——第一章环境安装下载(Windows)
windows·python·学习·pycharm
CS创新实验室1 小时前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
用户298698530142 小时前
Python 实现 Excel 到 ODS、XPS、PostScript 及 PDF/A-1b 的格式转换
后端·python·excel
本地化文档2 小时前
xlwings-docs-l10n
python·github·excel·gitcode·sphinx
逝水无殇2 小时前
C# 正则表达式详解
开发语言·后端·正则表达式·c#
朱永博2 小时前
使用Onnruntime实现Padim/Patchcore推理
开发语言·c#