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

Appearance settings

Latest commit

 

History

History
History
21 lines (20 loc) · 667 Bytes

File metadata and controls

21 lines (20 loc) · 667 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
Author: King,wangjingui@outlook.com
Date: Dec 25, 2014
Problem: Climbing Stairs
Difficulty: Easy
Source: https://oj.leetcode.com/problems/climbing-stairs/
Notes:
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Solution: Clime one step from last stair or clime 2 steps from the last last stair.
*/
public class Solution {
public int climbStairs(int n) {
int[] f = new int[n+1];
f[0] = 1; f[1] = 1;
for (int i = 2; i <= n; ++i)
f[i] = f[i-1] + f[i-2];
return f[n];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.