标签:leetcode
https://oj.leetcode.com/problems/climbing-stairs/
http://blog.csdn.net/linhuanmars/article/details/23976963
public class Solution {
public int climbStairs(int n)
{
// A recursive solution
// if (n == 1 || n == 2)
// {
// return 1;
// }
// return climbStairs(n - 1) + climbStairs(n - 2);
int[] solutions = new int[Math.max(n, 2)];
solutions[0] = 1;
solutions[1] = 2;
for (int i = 2 ; i < solutions.length ; i ++)
{
solutions[i] = solutions[i - 1] + solutions[i - 2];
}
return solutions[n - 1];
}
}标签:leetcode
原文地址:http://7371901.blog.51cto.com/7361901/1598899