70. Climbing Stairs

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     int climbStairs(int n) 
12     {
13         int count=2;
14         int feb1=1,feb2=1,cur;
15         while(count<=n)
16         {
17             cur=feb1+feb2;
18             count++;
19             feb1=feb2;
20             feb2=cur;
21         }
22         return n==1? 1:cur;
23     }
24 };

It's basically Fibonacci climbing the stairs

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324506719&siteId=291194637