提交时间:2023-11-25 11:31:09

运行 ID: 112287

class Solution { int process(int curr, int n){ if(curr == n){ return 1; } if(curr == n - 1){ return process(curr + 1, n); } return process(curr + 1, n) + process(curr + 2, n); } public: int climbStairs(int n) { if(n < 0){ return -1; } std::vector<int> dp(n + 1); dp[n] = 1; for (int curr = n - 1; curr >= 0; --curr) { if(curr == n - 1){ dp[curr] = dp[curr + 1]; }else{ dp[curr] = dp[curr + 1] + dp[curr + 2]; } } return dp[0]; } };