Skip to content

Commit 21da6f3

Browse files
committed
70. 爬楼梯
1 parent f4c4a75 commit 21da6f3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.geekidentity.leetcode.n0070;
2+
3+
/**
4+
* 70. 爬楼梯
5+
* https://leetcode-cn.com/problems/climbing-stairs/
6+
* 计算机只会运行判断和简单重复性问题,因此要找最近重复子问题
7+
*/
8+
public class ClimbStairs {
9+
10+
public int climbStairs(int n) {
11+
if (n <= 2) return n;
12+
int a = 1, b = 2, c = 3;
13+
for (int i = 3; i <= n; i++) {
14+
c = a + b;
15+
a = b;
16+
b = c;
17+
}
18+
return c;
19+
}
20+
}

0 commit comments

Comments
 (0)