Climbing Stairs

来源:互联网 发布:尖锐湿疣 知乎 编辑:程序博客网 时间:2024/05/21 09:04
-----QUESTION-----

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?

-----SOLUTION-----

class Solution {public:    int climbStairs(int n) {        int result[n+1];        result[0] = 1;        result[1] = 1;        int i =2;        while(i<=n)        {            result[i] = result[i-1]+result[i-2];            i++;        }        return result[n];            }};


0 0