Problem of Today: Climbing Stairs
Problem description: https://leetcode.com/problems/climbing-stairs/
Solution Approach: Memoization
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Solution { private int memo[]; // Bottom-up public int climbStairs(int n) { memo = new int[n+1]; for (int i=0; i<=n; i++) { memo[n] = -1; } memo[0] = 1; memo[1] = 1; for (int i=2; i<=n; i++) { memo[i] = memo[i-1] + memo[i-2]; } return memo[n]; } } |
Happy Coding!
Love! ❤️
#Lets #Code
Follow us on :
https://twitter.com/ThinkAlgorithms
No comments:
Post a Comment