Update 0070.爬楼梯.md

添加 0070.爬楼梯 Java版本
This commit is contained in:
kyrie 2021-05-15 12:30:37 +08:00 committed by GitHub
parent db785168ba
commit bd707f8938
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;
}
}
```
Python