Skip to content

Instantly share code, notes, and snippets.

@pdu
Created December 30, 2012 06:17
Show Gist options
  • Select an option

  • Save pdu/4411236 to your computer and use it in GitHub Desktop.

Select an option

Save pdu/4411236 to your computer and use it in GitHub Desktop.
class Solution {
public:
int climbStairs(int n) {
int f[3] = {1, 0, 0};
int cur = 0;
for (int i = 1; i <= n; ++i) {
cur = i % 3;
f[cur] = f[0] + f[1] + f[2] - f[cur];
}
return f[cur];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment