Skip to content

Instantly share code, notes, and snippets.

@novellizator
Created August 13, 2017 20:49
Show Gist options
  • Save novellizator/85e3f297a56d249d509346fe61a11bcd to your computer and use it in GitHub Desktop.
Save novellizator/85e3f297a56d249d509346fe61a11bcd to your computer and use it in GitHub Desktop.
staircase.c
/**
* @input A : Integer
*
* @Output Integer
*/
int climbStairs(int A) {
int* stairCase = malloc(A* sizeof(int));
int i;
for (i = 0; i < A; ++i) {
if (i == 0) {
stairCase[i] = 1;
continue;
}
if (i == 1) {
stairCase[i] = 2;
continue;
}
stairCase[i] = stairCase[i - 2] + stairCase[i - 1];
}
int ret = stairCase[A - 1];
free(stairCase);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment