题目
题目来源:https://leetcode-cn.com/problems/fibonacci-number/
完整代码
public class SolutionTest {
public static void main(String[] args){
Solution slt = new Solution();
System.out.println(slt.fib(2));
}
}
class Solution {
public int fib(int n) {
int[] feibonaqie = new int[n+1];
if(n == 0){
return 0;
}
if(n == 1){
return 1;
}
feibonaqie[0] = 0;
feibonaqie[1] = 1;
for(int i = 2; i <= n; i++){
feibonaqie[i] = feibonaqie[i-1]+feibonaqie[i-2];
}
return feibonaqie[n];
}
}