Leetcode#70 Climbing Stairs

原题地址

 

基本动归题

可以压缩状态空间

 

代码:

 1 int climbStairs(int n) {

 2         if (n <= 0)

 3             return 0;

 4             

 5         int count = 1;

 6         int tmp = 1;

 7         

 8         for (int i = 2; i <= n; i++) {

 9             int t = count;

10             count += tmp;

11             tmp = t;

12         }

13         

14         return count;

15 }

 

你可能感兴趣的:(LeetCode)