diff options
-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)); + } +} |