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 };
本质就是斐波那契爬楼梯