We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4c4a75 commit 21da6f3Copy full SHA for 21da6f3
src/main/java/com/geekidentity/leetcode/n0070/ClimbStairs.java
@@ -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