首页 > 其他 > 详细

【Leetcode_easy】1137. N-th Tribonacci Number

时间:2019-07-30 20:07:38      阅读:102      评论:0      收藏:0      [点我收藏+]

problem

solution:

class Solution {
public:
    int tribonacci(int n) {
        if(n==0) return 0;
        if(n==1 || n==2) return 1;
        int t0 = 0, t1 = 1, t2 = 1, t3 = 0;
        for(int i=3; i<=n; i++)
        {
            t3 = t0+t1+t2;
            t0 = t1;
            t1 = t2;
            t2 = t3;          
        }
        return t3;
    }
};

 

 
 
参考

【Leetcode_easy】1137. N-th Tribonacci Number

原文:https://www.cnblogs.com/happyamyhope/p/11272315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!