05 August 2008
斐波那契数三个数的情况
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
Map<Integer, Integer> map = new HashMap<>();
public int tribonacci(int n) {
if (n < 2) {
return n;
}
if (n == 2) {
return 1;
}
if (!map.containsKey(n)) {
map.put(n, tribonacci(n - 1) + tribonacci(n - 2) + tribonacci(n - 3));
}
return map.get(n);
}
}