We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5dad3f commit 9aee0adCopy full SHA for 9aee0ad
leetcode/src/1137.c
@@ -1,7 +1,4 @@
1
-// Dynamic Programming
2
-// Runtime: O(n)
3
-// Space: O(1)
4
-int tribonacci(int n){
+int tribonacci(int n) {
5
int t0 = 0;
6
int t1 = 1;
7
int t2 = 1;
@@ -10,19 +7,19 @@ int tribonacci(int n){
10
return t0;
11
8
}
12
9
13
- if (n == 1){
+ if (n == 1) {
14
return t1;
15
16
17
- if (n == 2){
+ if (n == 2) {
18
return t2;
19
20
21
- for (int i = 0; i < n - 2; i++){
22
- int nextT = t0 + t1 + t2;
+ for (int i = 3; i <= n; i++) {
+ int nextTerm = t0 + t1 + t2;
23
t0 = t1;
24
t1 = t2;
25
- t2 = nextT;
+ t2 = nextTerm;
26
27
28
0 commit comments