70. Climbing Stairs

问题描述

解决方案

我的解决方法

class Solution {
public:
    int climbStairs(int n) {
        int a=1,b=1;
        for(int i=1;i<n;++i)
        {
            b+=a;
            a=b-a;
        }
        return b;
    }
};

网上的解决方法

class Solution {
public:
    int climbStairs(int n) {
        return (pow((1.0+sqrt(5.0))/2.0,n+1)-pow((1.0-sqrt(5.0))/2.0,n+1))/sqrt(5.0);
    }
};

posted @ 2016-08-26 11:16  弦断  阅读(195)  评论(0编辑  收藏  举报