Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions leetcode/src/1137.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Dynamic Programming
// Runtime: O(n)
// Space: O(1)
int tribonacci(int n){
int tribonacci(int n) {
int t0 = 0;
int t1 = 1;
int t2 = 1;
Expand All @@ -10,19 +7,19 @@ int tribonacci(int n){
return t0;
}

if (n == 1){
if (n == 1) {
return t1;
}

if (n == 2){
if (n == 2) {
return t2;
}

for (int i = 0; i < n - 2; i++){
int nextT = t0 + t1 + t2;
for (int i = 3; i <= n; i++) {
int nextTerm = t0 + t1 + t2;
t0 = t1;
t1 = t2;
t2 = nextT;
t2 = nextTerm;
}

return t2;
Expand Down
Loading