Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e9cb18

Browse files
author
applewjg
committed
ClimbingStairs
Change-Id: I1dd45e00245c9ea207db9fdbf13934dda4a428ca
1 parenta22816d commit6e9cb18

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,wangjingui@outlook.com
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+
publicclassSolution {
14+
publicintclimbStairs(intn) {
15+
int[]f =newint[n+1];
16+
f[0] =1;f[1] =1;
17+
for (inti =2;i <=n; ++i)
18+
f[i] =f[i-1] +f[i-2];
19+
returnf[n];
20+
}
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp