A clear C++ approach. 1ms.


  • 0
    Y
    class Solution {
    public:
        int climbStairs(int n) {
        	int sum[n];
        	sum[0]=1;sum[1]=2;sum[2]=3;
        	for(int i=3;i<n;i++){
        		sum[i]=sum[i-3]+sum[i-2]*2;
        	}
        	return sum[n-1];
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.