leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1414.cpp (559B)
0 class Solution {
1 typedef array<int, 45> cache_t;
2 static inline constexpr const cache_t cache = []() constexpr -> cache_t {
3 cache_t cache;
4 cache[0] = cache[1] = 1;
5 for (int i = 2; i < cache.size(); i++)
6 cache[i] = cache[i - 1] + cache[i - 2];
7 return cache;
8 }();
10 public:
11 int findMinFibonacciNumbers(int k) {
12 int res = 0;
13 for (auto it = upper_bound(begin(cache), end(cache), k); k > 0; it--)
14 while (k >= *it)
15 k -= *it, res++;
16 return res;
17 }
18 };