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 acd7746 commit cc5824eCopy full SHA for cc5824e
βclimbing-stairs/river20s.java
@@ -0,0 +1,26 @@
1
+/*
2
+ * νμ΄: nλ²μ§Έ κ³λ¨μ λλ¬νλ κ²½μ°λ λ€μ λ κ°μ§λ‘ λλλ€.
3
+ * 1. (n-1)λ²μ§Έ κ³λ¨μμ ν κ³λ¨ μ€λ₯΄λ κ²½μ°
4
+ * 2. (n-2)λ²μ§Έ κ³λ¨μμ λ κ³λ¨ μ€λ₯΄λ κ²½μ°
5
+ * λ°λΌμ, nκ°μ κ³λ¨μ μ¬λΌκ°λ λ°©λ²μ κ²½μ°μ μ F(n)μ
6
+ * F(n-1)κ³Ό F(n-2)μ ν©κ³Ό κ°λ€.
7
+ * μκ° λ³΅μ‘λ: O(n)
8
+ * κ³΅κ° λ³΅μ‘λ: O(1)
9
+ */
10
+class Solution {
11
+ public int climbStairs(int n) {
12
+ if(n == 1) return 1;
13
+
14
+ int step1 = 1;
15
+ int step2 = 2;
16
17
+ for (int i = 3; i <= n; i++) {
18
+ int temp = step1 + step2;
19
+ step1 = step2;
20
+ step2 = temp;
21
+ }
22
23
+ return step2;
24
25
+}
26
0 commit comments