Skip to content

Commit

Permalink
✨ solve 1137
Browse files Browse the repository at this point in the history
  • Loading branch information
Potato Chip committed Nov 12, 2021
1 parent 2a8b409 commit 0e33644
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 1137.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// https://leetcode.com/problems/n-th-tribonacci-number/

#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
int tribonacci(int n) {
int a = 0;
int b = 1;
int c = 1;

for (int i = 2; i < n; ++i) {
int bb = b;
c = a + b + c;
b = c - (b + a);
a = bb;
}

if (n == 0) {
return a;
} else if (n == 1) {
return b;
} else {
return c;
}
}
};

0 comments on commit 0e33644

Please sign in to comment.