Created
March 16, 2017 20:05
-
-
Save vitkarpov/a45fd7c2dbf64e19dc923a4afdeb7dfd to your computer and use it in GitHub Desktop.
"Cracking the coding interview", 8.1
This file contains hidden or 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
/** | |
* Находит количество всех возможных вариантов | |
* как можно добраться до n-й ступени по лестнице, | |
* если можно пройти 1, 2 или 3 ступени за один шаг. | |
* | |
* @param {number} n | |
* @returns {number} | |
*/ | |
function countWays(n) { | |
if (n < 0) { | |
return 0; | |
} | |
if (n === 0) { | |
return 1; | |
} | |
return countWays(n - 1) + countWays(n - 2) + countWays(n - 3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment