From 48c08c6f52cf167c750ad34ae8d2867d485a68d4 Mon Sep 17 00:00:00 2001 From: Khushi <58480229+khushi200701@users.noreply.github.com> Date: Tue, 12 Oct 2021 11:08:16 +0530 Subject: [PATCH] climbing-stairs-leetcode --- climbing-stairs.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 climbing-stairs.java diff --git a/climbing-stairs.java b/climbing-stairs.java new file mode 100644 index 0000000..e293edc --- /dev/null +++ b/climbing-stairs.java @@ -0,0 +1,22 @@ +// https://leetcode.com/problems/climbing-stairs/ + +public class Solution { + public int climbStairs(int n) { + + return climb_Stairs(0, n, new int[n + 1]); + } + + public int climb_Stairs(int i, int n, int dp[]) { + if (i > n) { + return 0; + } + if (i == n) { + return 1; + } + if (dp[i] > 0) { + return dp[i]; + } + dp[i] = climb_Stairs(i + 1, n, dp) + climb_Stairs(i + 2, n, dp); + return dp[i]; + } +} \ No newline at end of file