Last active
April 2, 2026 18:06
-
-
Save thinkphp/679d1870fd2ac3009cda527a40f0beca to your computer and use it in GitHub Desktop.
climbing Stairs - introducere in Programare dinamica; sirul lui fibonacci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int climbingStairs(int n) { | |
| int dp[] = new int[n+1]; | |
| Arrays.fill(dp, -1); | |
| return solve(n, dp); | |
| } | |
| public int solve(int n, int[] dp) { | |
| if(n == 0) return 1; | |
| if(n < 0) { | |
| return 0; | |
| } | |
| if(dp[n]!=-1) { | |
| return dp[n]; | |
| } | |
| dp[n] = solve(n-1, dp) + solve(n-2, dp); | |
| return dp[n]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment