Created
July 31, 2020 23:20
-
-
Save munguial/46700b03beedd2d4a3f9421eded73d1e to your computer and use it in GitHub Desktop.
July - Day 31 - Climbing Stairs
This file contains 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
// https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/548/week-5-july-29th-july-31st/3407/ | |
import java.util.*; | |
public class Solution { | |
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>(); | |
public int climbStairs(int n) { | |
if(n == 0) | |
return 1; | |
if(n < 0) | |
return 0; | |
if(map.containsKey(n)) | |
return map.get(n); | |
int left = climbStairs(n - 1); | |
int right = climbStairs(n - 2); | |
int sum = left + right; | |
map.put(n, sum); | |
return sum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment