LeetCode_Climbing Stairs

 1 class Solution {
 2 public:
 3     int climbStairs(int n) {
 4         // Start typing your C/C++ solution below
 5         // DO NOT write int main() function
 6         if(n ==0) return 0;
 7         if(n == 1) return 1;
 8         if(n == 2) return 2;
 9         int a1 = 1;
10         int a2 = 2;
11         int a3;
12         for(int i =3;i<=n; i++)
13         {    
14             a3 = a1+ a2;
15             a1 = a2;
16             a2 = a3;
17         }
18         
19         return a3;
20     }
21 };
--------------------------------------------------------------------天道酬勤!
原文地址:https://www.cnblogs.com/graph/p/3006549.html