Skip to content

Instantly share code, notes, and snippets.

@munguial
Created July 31, 2020 23:20
Show Gist options
  • Save munguial/46700b03beedd2d4a3f9421eded73d1e to your computer and use it in GitHub Desktop.
Save munguial/46700b03beedd2d4a3f9421eded73d1e to your computer and use it in GitHub Desktop.
July - Day 31 - Climbing Stairs
// 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