其他分享
首页 > 其他分享> > 1137. 第 N 个泰波那契数

1137. 第 N 个泰波那契数

作者:互联网

题目

来源:1137. 第 N 个泰波那契数 - 力扣(LeetCode) (leetcode-cn.com)

题目描述:

完整代码

public class SolutionTest {
    public static void main(String[] args){
        Solution slt = new Solution();
        System.out.println(slt.tribonacci(5));
    }
}


class Solution {
    public int tribonacci(int n) {
        if(n==0)
            return 0;
        if(n==1)
            return 1;
        if(n==2)
            return 1;

        int[] taibonaqie = new int[n+1];

        taibonaqie[0] = 0;
        taibonaqie[1] = 1;
        taibonaqie[2] = 1;

        for(int i = 3; i <= n; i++){
            taibonaqie[i] = taibonaqie[i-1]+taibonaqie[i-2]+taibonaqie[i-3];
        }

        return taibonaqie[n];
    }
}

标签:契数,return,int,个泰波,1137,Solution,tribonacci,taibonaqie,public
来源: https://www.cnblogs.com/taote/p/15410435.html