LeetCode 070 Climbing Stairs

来源:互联网 发布:传输网络结构 编辑:程序博客网 时间:2024/05/29 13:38

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Note: Given n will be a positive integer.

第一次AC代码如下:

class Solution {//斐波那契数列变种public:    int climbStairs(int n) {//时间复杂度O(n)、空间复杂度O(n)        int* array=new int[n+1];        array[1]=1;        array[2]=2;        for(int i=3;i<=n;i++)            array[i]=array[i-1]+array[i-2];        return array[n];    }};



0 0
原创粉丝点击