leetcode Climbing Stairs


class Solution {
public:
    int climbStairs(int n) {
        if(n == 0) return 0;
        if(n == 1) return 1;
        if(n == 2) return 2;
        
        int prepre = 1; 
        int pre = 2;
        int cur = 0;
        for(int i = 3;i <= n;i ++) {
        	cur = prepre + pre;
        	prepre = pre;
        	pre = cur;	
		}
		return cur;
        
    }
};


你可能感兴趣的:(leetcode Climbing Stairs)