Skip to content

Commit 95d1435

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 509_Fibonacci_Number.java
1 parent b32e4cf commit 95d1435

File tree

1 file changed

+17
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)