Skip to content

Commit 6e9cb18

Browse files
author
applewjg
committed
ClimbingStairs
Change-Id: I1dd45e00245c9ea207db9fdbf13934dda4a428ca
1 parent a22816d commit 6e9cb18

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ClimbingStairs.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)