Created
August 13, 2017 20:49
-
-
Save novellizator/85e3f297a56d249d509346fe61a11bcd to your computer and use it in GitHub Desktop.
staircase.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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