Simple DP Java Solution


  • 0
    Z
        public class Solution {
    	public int climbStairs(int n){
    		int map[] = new int[n + 1];
    		return climbStairs(n , map);
    	}
    	
    	public int climbStairs(int n, int[] map){
    		if(n <= 2){
    			map[n] = n;
    			return map[n];
    		}
    		if(map[n] == 0){
    			map[n] = climbStairs(n - 1, map) + climbStairs(n - 2, map);
    		}
    		return map[n];
    	}
    }
    

    The question is basically asking about the fibonacci number for a given input. This solution is a recursive dp approach.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.