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
相关推荐
Sirius.z10 小时前
第R6周:LSTM实现糖尿病探索与预测
python
名字还没想好☜10 小时前
Python f-string 进阶:数字格式化、对齐填充、调试 = 号与嵌套表达式
开发语言·数据库·python·字符串格式化·f-string
·薯条大王10 小时前
经济实惠玩云服务器|一台云服务器多人共用,子账号配置教程
java·linux·运维·服务器·汇编·c++·python
Dxy123931021611 小时前
Python 如何使用 MySQL 的事务
python·mysql
一壶浊酒..13 小时前
Scrape Webpack练习
开发语言·javascript·webpack
命运之光14 小时前
【C语言完整代码】就诊信息管理系统
java·c语言·开发语言
命运之光14 小时前
【C语言完整代码】图书管理系统:图书馆场景下的增删改查实战
c语言·开发语言
猿长大人14 小时前
C# | Serilog 新手入门
开发语言·c#·.net·log
今儿敲了吗15 小时前
Python ——第三方包
笔记·python
麒麟水手15 小时前
国产银河麒麟系统开发实录:跑通Streamlit,我踩过的6个坑
python