Skip to content

Commit

Permalink
Update 0509.斐波那契数.md
Browse files Browse the repository at this point in the history
增加java非压缩状态版本,易于理解
  • Loading branch information
hailincai authored Oct 24, 2021
1 parent f9abccf commit 6183852
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/0509.斐波那契数.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@ class Solution {
}
```

```java
//非压缩状态的版本
class Solution {
public int fib(int n) {
if (n <= 1) return n;

int[] dp = new int[n + 1];

dp[0] = 0;
dp[1] = 1;

for (int index = 2; index <= n; index++){
dp[index] = dp[index - 1] + dp[index - 2];
}

return dp[n];
}
}
```

Python:
```python3
class Solution:
Expand Down

0 comments on commit 6183852

Please sign in to comment.