Sunday, 20 December 2015

LeetCode Climbing Stairs! like fabonacci series from last point

LeetCode Climbing Stairs! like fabonacci series from last point 

class Solution {

public:

    int climbStairs(int n) {

        if(n<=3)

         return n;

        int i=3,j=2;

        int temp;

        int cnt=3;

        while(cnt<n)

         {

             temp=i;

             i=i+j;

             j=temp;

             cnt++;

         }

         return i;

    }

};

No comments:

Post a Comment