标签:
This is pretty simple.
Just use three element to pretain the result;
1 class Solution { 2 public: 3 int climbStairs(int n) { 4 vector<int> dp(3, 1); 5 for (int i = 2; i <= n; i++) { 6 dp[0] = dp[1]; 7 dp[1] = dp[2]; 8 dp[2] += dp[0]; 9 } 10 return dp[2]; 11 } 12 };
LeetCode – Refresh – Climbing Stairs
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/4346278.html