Skip to content

Commit 64f19bb

Browse files
committed
Time: 0 ms (100.00%) | Memory: 8 MB (51.87%) - LeetSync
1 parent 0275866 commit 64f19bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int tribonacci(int n) {
4+
if(n==0) return 0;
5+
if(n==1 || n==2) return 1;
6+
int a=0, b=1, c=1, result=0;
7+
for(int i=3; i<=n; i++){
8+
result = a+b+c;
9+
a=b;
10+
b=c;
11+
c=result;
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)