Easy DP Solution


  • 0
    5

    public class Solution {
    public int climbStairs(int n) {
    int [] sum = new int[n + 1];
    if(n < 2) {
    return 1;
    }
    sum[0] = 1;
    sum[1] = 1;
    sum[2] = 1;

    	for(int i = 2; i< sum.length; i++) {
    		sum[i] = sum[i - 1] + sum[i - 2];
    	}
    	
    	return sum[n];
    }
    

    }


Log in to reply
 

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