leetcode 70
简单的递推
1 class Solution { 2 public: 3 int climbStairs(int n) { 4 if(n==0)return 0; 5 if(n==1)return 1; 6 if(n==2)return 2; 7 int a=1,b=2,c; 8 for(int i=3;i<=n;i++) { 9 c=a+b; 10 a=b; 11 b=c; 12 } 13 return c; 14 } 15 };
简单的递推
1 class Solution { 2 public: 3 int climbStairs(int n) { 4 if(n==0)return 0; 5 if(n==1)return 1; 6 if(n==2)return 2; 7 int a=1,b=2,c; 8 for(int i=3;i<=n;i++) { 9 c=a+b; 10 a=b; 11 b=c; 12 } 13 return c; 14 } 15 };