Skip to content

Instantly share code, notes, and snippets.

@vitkarpov
Created March 16, 2017 20:05
Show Gist options
  • Save vitkarpov/a45fd7c2dbf64e19dc923a4afdeb7dfd to your computer and use it in GitHub Desktop.
Save vitkarpov/a45fd7c2dbf64e19dc923a4afdeb7dfd to your computer and use it in GitHub Desktop.
"Cracking the coding interview", 8.1
/**
* Находит количество всех возможных вариантов
* как можно добраться до 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