Merge pull request #133 from KyrieChang/patch-3

Update 0070.爬楼梯.md Java 版本
This commit is contained in:
Carl Sun 2021-05-15 17:39:40 +08:00 committed by GitHub
commit 78f2e7602b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -212,6 +212,22 @@ public:
Java
```Java
class Solution {
public int climbStairs(int n) {
// 跟斐波那契数列一样
if(n <= 2) return n;
int a = 1, b = 2, sum = 0;
for(int i = 3; i <= n; i++){
sum = a + b;
a = b;
b = sum;
}
return b;
}
}
```
```java
// 常规方式