【leetcode】第 N 个泰波那契数

 

int tribonacci(int n){
    if (n == 0) return 0;
    else if (n == 1 || n == 2) return 1;
    int t0=0, t1=1,t2=1,i,num=0;
    for (i=3; i<=n; i++)
    {
        num = t0 + t1 + t2;
        t0 = t1;
        t1 = t2;
        t2 = num;
    }
    return num;
}

 

posted @ 2020-09-15 17:06  温暖了寂寞  阅读(99)  评论(0编辑  收藏  举报