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

Commit 68f5e49

Browse filesBrowse files
Implementation for ClimbingStairs problem using DP
1 parent cca7a6b commit 68f5e49
Copy full SHA for 68f5e49

File tree

Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-0
lines changed

‎ClimbingStairs.java

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class ClimbingStairs {
2+
public int climbStairs(int n) {
3+
if (n == 1) {
4+
return 1;
5+
}
6+
int[] dp = new int[n + 1];
7+
dp[1] = 1;
8+
dp[2] = 2;
9+
for (int i = 3; i <= n; i++) {
10+
dp[i] = dp[i - 1] + dp[i - 2];
11+
}
12+
return dp[n];
13+
}
14+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.