lurenaa的博客

😂自顶向下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int climbStairs(int n) {
f.resize(1000);
f[1] = 1;
f[2] = 2;
return helper(n);
}
int helper(int n) {
if(f[n] || n <= 2)
return f[n];
f[n] = helper(n - 1) + helper(n-2);
return f[n];
}
private:
vector<int> f;
};

Accepted

45/45 cases passed (0 ms)

Your runtime beats 100 % of cpp submissions

Your memory usage beats 5.03 % of cpp submissions (8.7 MB)