1414. 和为 K 的最少斐波那契数字数目

题目链接:https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/

执行用时:2 ms, 在所有 Java 提交中击败了61.00% 的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int findMinFibonacciNumbers(int k) {
ArrayList<Integer> array = new ArrayList<>();
int last = 0, cur = 1, next = 0;
while (cur <= k) {
array.add(cur);
next = last + cur;
last = cur;
cur = next;
}
int count = 0;
for (int i = array.size()-1; i >= 0 ; i--) {
if (k - array.get(i) >= 0) {
k -= array.get(i);
count++;
}
}
return count;
}
}


1414. 和为 K 的最少斐波那契数字数目
https://pisces34.github.io/2022/02/03/leetcode/1414/
发布于
2022年2月3日
许可协议