您的位置:首页 > 大数据 > 人工智能

[LeetCode]70 Climbing Stairs

2015-01-04 11:06 513 查看
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