diff options
author | Michael Hunteman <michael@huntm.net> | 2022-10-26 21:16:53 -0500 |
---|---|---|
committer | Michael Hunteman <michael@huntm.net> | 2022-10-26 21:16:53 -0500 |
commit | bc54099da2f9252031f49ed546922fa057288e7f (patch) | |
tree | a5cb75423a12cc07a4221ee2e37df2b821dba9fe | |
parent | 0fab296dca50965ceb04972db4505ea375592478 (diff) |
Add Climbing Stairs
-rw-r--r-- | ClimbingStairs.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ClimbingStairs.java b/ClimbingStairs.java new file mode 100644 index 0000000..f03a06b --- /dev/null +++ b/ClimbingStairs.java @@ -0,0 +1,18 @@ +import java.lang.*; +import java.util.*; + +class ClimbingStairs { + public static int climbStairs(int n) { + int[] dp = new int[n + 1]; + dp[0] = 1; + dp[1] = 1; + for (int i = 2; i <= n; i++) { + dp[i] = dp[i - 1] + dp[i - 2]; + } + return dp[n]; + } + + public static void main(String[] args) { + System.out.println(climbStairs(5)); + } +} |