Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6183852

Browse files
authored
Update 0509.斐波那契数.md
增加java非压缩状态版本,易于理解
1 parent f9abccf commit 6183852

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

problems/0509.斐波那契数.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,26 @@ class Solution {
186186
}
187187
```
188188

189+
```java
190+
//非压缩状态的版本
191+
class Solution {
192+
public int fib(int n) {
193+
if (n <= 1) return n;
194+
195+
int[] dp = new int[n + 1];
196+
197+
dp[0] = 0;
198+
dp[1] = 1;
199+
200+
for (int index = 2; index <= n; index++){
201+
dp[index] = dp[index - 1] + dp[index - 2];
202+
}
203+
204+
return dp[n];
205+
}
206+
}
207+
```
208+
189209
Python:
190210
```python3
191211
class Solution:

0 commit comments

Comments
 (0)