当前位置:网站首页>Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
2022-07-06 06:18:00 【Encounter simulation volume】
Summary : Simulation volume Leetcode Summary of questions
1414. And for K The minimum number of Fibonacci Numbers
Here are the numbers k , Please return and for k The minimum number of Fibonacci numbers , among , Each Fibonacci number can be used many times .
Fibonacci numbers are defined as :
F1 = 1
F2 = 1
Fn = Fn-1 + Fn-2 , among n > 2 .
Data guarantee for a given k , A feasible solution must be found .
Example 1:
Input :k = 7
Output :2
explain : Fibonacci number is :1,1,2,3,5,8,13,……
about k = 7 , We can get 2 + 5 = 7 .
Example 2:
Input :k = 10
Output :2
explain : about k = 10 , We can get 2 + 8 = 10 .
Example 3:
Input :k = 19
Output :3
explain : about k = 19 , We can get 1 + 5 + 13 = 19 .
Tips :
1 <= k <= 10^9
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Code :
from leetcode_python.utils import *
class Solution:
def findMinFibonacciNumbers(self, k: int) -> int:
f = [1,1]
while f[-1]<k:f.append(f[-1]+f[-2])
res,i = 0,len(f)-1
while k:
if k>=f[i]:
k-=f[i]
res+=1
i-=1
return res
def test(data_test):
s = Solution()
data = data_test # normal
# data = [list2node(data_test[0])] # list turn node
return s.getResult(*data)
def test_obj(data_test):
result = [None]
obj = Solution(*data_test[1][0])
for fun, data in zip(data_test[0][1::], data_test[1][1::]):
if data:
res = obj.__getattribute__(fun)(*data)
else:
res = obj.__getattribute__(fun)()
result.append(res)
return result
if __name__ == '__main__':
datas = [
[],
]
for data_test in datas:
t0 = time.time()
print('-' * 50)
print('input:', data_test)
print('output:', test(data_test))
print(f'use time:{
time.time() - t0}s')
remarks :
GitHub:https://github.com/monijuan/leetcode_python
CSDN Summary : Simulation volume Leetcode Summary of questions
You can add QQ Group communication :1092754609
leetcode_python.utils See the description on the summary page for details
First brush questions , Then generated by script blog, If there is any mistake, please leave a message , I see it will be revised ! thank you !
边栏推荐
- Properties file
- On weak network test of special test
- 联合索引的左匹配原则
- 进程和线程的理解
- 模拟卷Leetcode【普通】1249. 移除无效的括号
- Career advancement Guide: recommended books for people in big factories
- 这些年用Keil遇到的坑
- Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
- An article was uncovered to test the truth of outsourcing companies
- 技术分享 | 常见接口协议解析
猜你喜欢

黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)

Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?

数字三角形模型 AcWing 1015. 摘花生

JWT-JSON WEB TOKEN

Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete

E - 食物链

Pat (Grade B) 2022 summer exam
![[ram IP] introduction and experiment of ram IP core](/img/34/1c988456e32a8e9840d1d073caefbf.jpg)
[ram IP] introduction and experiment of ram IP core

异常检测方法总结

Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
随机推荐
数字三角形模型 AcWing 1015. 摘花生
Expose the serial fraudster Liu Qing in the currency circle, and default hundreds of millions of Cheng Laolai
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
Hypothesis testing learning notes
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
技术分享 | 常见接口协议解析
P问题、NP问题、NPC问题、NP-hard问题详解
IP day 16 VLAN MPLS configuration
D - How Many Answers Are Wrong
数据库隔离级别
把el-tree选中的数组转换为数组对象
Nodejs realizes the third-party login of Weibo
[postman] the monitors monitoring API can run periodically
进程和线程的理解
模拟卷Leetcode【普通】1143. 最长公共子序列
Understanding of processes and threads
What are the test sites for tunnel engineering?
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)