Skip to content

Commit

Permalink
70_new.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
llinvokerl committed Feb 27, 2019
1 parent ff1398e commit 8f45b29
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 70_new.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int climbStairs(int n) {
vector<int> table(n + 1, -1);
return helper(n, table);
}
int helper(int n, vector<int> &table) {
if (n <= 1) {
return 1;
}
if (table[n] != -1) {
return table[n];
}
return table[n] = helper(n - 1, table) + helper(n - 2, table);
}
};

0 comments on commit 8f45b29

Please sign in to comment.