独孤凌雪

关注

【Leetcode_easy】1137. N-th Tribonacci Number

独孤凌雪

关注

阅读 72

2022-07-12

problem

​​1137. N-th Tribonacci Number​​

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;
}
};

 

 

 

参考

1. ​​Leetcode_easy_1137. N-th Tribonacci Number​​;

完

相关推荐

Go_Viola

LeetCode 1137.第 N 个泰波那契数(简单)

Go_Viola 82 0 0

乌龙茶3297

【leetcode_easy】1189. Maximum Number of Balloons

乌龙茶3297 70 0 0

做个橙梦

【Leetcode_easy】693. Binary Number with Alternating Bits

做个橙梦 25 0 0

大沈投资笔记

Leetcode 1137. 第 N 个泰波那契数

大沈投资笔记 48 0 0

yongxinz

【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation

yongxinz 29 0 0

朱小落

2022.3.18 leetcode刷题笔记 1137. 第 N 个泰波那契数

朱小落 50 0 0

早安地球

LeetCode 训练场:1137. 第 N 个泰波那契数

早安地球 59 0 0

软件共享软件

【Leetcode_easy】690. Employee Importance

软件共享软件 92 0 0

骨灰级搬砖工

【Leetcode_easy】1051. Height Checker

骨灰级搬砖工 203 0 0

王小沫

【Leetcode_easy】706. Design HashMap

王小沫 112 0 0

精彩评论(0)

0 0 举报