Skip to content

斐波那契数列

比较经典的一类题型,记录一下最容易理解的递归写法。但数据特别大时,就是超过int的取值范围,此写法会出错。

java
class Solution {
    public int fib(int n) {
        if(n == 1){
            return 1;
        }
        if(n == 0){
            return 0;
        }
        int m = fib(n-1) + fib(n-2);
        return m;
    }
}

贡献者

The avatar of contributor named as 四季夏目 四季夏目
The avatar of contributor named as Claude Opus 4.5 Claude Opus 4.5

页面历史

最近更新

基于 VitePress 搭建