Skip to content

Commit 5d95fa0

Browse files
authored
Create 02 - Top-Down Approach.cpp
1 parent 65a407d commit 5d95fa0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int nthFibonacci(int n) {
4+
vector<int> dp(n+1, -1);
5+
6+
if(n == 1 || n == 0) return n;
7+
if(dp[n] != -1) return dp[n];
8+
9+
dp[n] = nthFibonacci(n-1) + nthFibonacci(n-2);
10+
11+
return dp[n];
12+
}
13+
};

0 commit comments

Comments
 (0)