Skip to content

Instantly share code, notes, and snippets.

@Cee
Created May 29, 2014 01:16
Show Gist options
  • Save Cee/dfeb843a916b78a4bbe3 to your computer and use it in GitHub Desktop.
Save Cee/dfeb843a916b78a4bbe3 to your computer and use it in GitHub Desktop.
public class Solution {
public int climbStairs(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
int ret = 0;
int tempa = 2;
int tempb = 1;
for (int i = 3; i <= n; i++){
ret = tempa + tempb;
tempb = tempa;
tempa = ret;
}
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment