Skip to content

Commit 9aee0ad

Browse files
Update 1137.c
1 parent e5dad3f commit 9aee0ad

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

leetcode/src/1137.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Dynamic Programming
2-
// Runtime: O(n)
3-
// Space: O(1)
4-
int tribonacci(int n){
1+
int tribonacci(int n) {
52
int t0 = 0;
63
int t1 = 1;
74
int t2 = 1;
@@ -10,19 +7,19 @@ int tribonacci(int n){
107
return t0;
118
}
129

13-
if (n == 1){
10+
if (n == 1) {
1411
return t1;
1512
}
1613

17-
if (n == 2){
14+
if (n == 2) {
1815
return t2;
1916
}
2017

21-
for (int i = 0; i < n - 2; i++){
22-
int nextT = t0 + t1 + t2;
18+
for (int i = 3; i <= n; i++) {
19+
int nextTerm = t0 + t1 + t2;
2320
t0 = t1;
2421
t1 = t2;
25-
t2 = nextT;
22+
t2 = nextTerm;
2623
}
2724

2825
return t2;

0 commit comments

Comments
 (0)