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 a22816d commit 6e9cb18Copy full SHA for 6e9cb18
ClimbingStairs.java
@@ -0,0 +1,21 @@
1
+/*
2
+ Author: King,[email protected]
3
+ Date: Dec 25, 2014
4
+ Problem: Climbing Stairs
5
+ Difficulty: Easy
6
+ Source: https://oj.leetcode.com/problems/climbing-stairs/
7
+ Notes:
8
+ You are climbing a stair case. It takes n steps to reach to the top.
9
+ Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
10
+
11
+ Solution: Clime one step from last stair or clime 2 steps from the last last stair.
12
+ */
13
+public class Solution {
14
+ public int climbStairs(int n) {
15
+ int[] f = new int[n+1];
16
+ f[0] = 1; f[1] = 1;
17
+ for (int i = 2; i <= n; ++i)
18
+ f[i] = f[i-1] + f[i-2];
19
+ return f[n];
20
+ }
21
+}
0 commit comments