Thursday, November 28, 2013

Climbing Stairs LeetCode

简单DP题很简单。


public int climbStairs(int n) {
        int[] result = new int[n+1];
        result[0] = 1;
        result[1] = 1;
        for(int i=2; i <n+1; i++){
            result[i]=result[i-1] + result[i-2];
        }
        return result[n];
    }

No comments:

Post a Comment