mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Update 0070.爬楼梯.md
添加 0070.爬楼梯 Java版本
This commit is contained in:
@ -212,6 +212,22 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
Java:
|
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:
|
Python:
|
||||||
|
Reference in New Issue
Block a user