Skip to content

Commit

Permalink
Time: 0 ms (100.00%), Space: 41 MB (45.05%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunalkshrivastava committed Apr 2, 2022
1 parent 2e9ca26 commit fc43a81
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 509-fibonacci-number/509-fibonacci-number.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int fib1(int n, int[] a){
if(n <= 1){
a[n] = n;
return n;
}
if(a[n] != 0) return a[n];

int ans = fib1(n-1,a) + fib1(n-2,a);
a[n] = ans;
return a[n];
}
public int fib(int n) {
int[] a = new int[n+1];

return fib1(n,a);
}
}

0 comments on commit fc43a81

Please sign in to comment.