Skip to content

Commit a9f12b6

Browse files
committed
[feat ]: leetcode 1137
Signed-off-by: Bo-Wei Chen(BWbwchen) <tim.chenbw@gmail.com>
1 parent f610425 commit a9f12b6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int tribonacci(int n) {
4+
if (n == 0)
5+
return 0;
6+
else if (n < 3)
7+
return 1;
8+
vector<int> v(n+1, 0);
9+
v[0] = 0;
10+
v[1] = 1;
11+
v[2] = 1;
12+
for (int i = 3; i <= n; ++i) {
13+
v[i] = v[i-1] + v[i-2] + v[i-3];
14+
}
15+
return v[n];
16+
}
17+
};

0 commit comments

Comments
 (0)