Skip to content

Commit 84e8e70

Browse files
authored
Create 509. Fibonacci Number
1 parent af87702 commit 84e8e70

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

509. Fibonacci Number

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

0 commit comments

Comments
 (0)