/
githubmirror
/
interviews
Обзор
Документация
Войти
/
githubmirror
/
interviews
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
cracking-the-coding-interview/chapter-nine-recursion-and-dynamic-programming/Staircase.java
22 строки
545 B
Kevin Naughton Jr
finish renaming files and directories
27 мар 2018, 19:52
27 мар 2018, 19:52
ec6dfb5
Код
Авторство
О чём код?
/* a child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps * at a time. Implement a method to count how many possible ways the child can run up the stairs */ public class Staircase { public static int countWaysDP(int n, int[] map) { if(n < 0) { return 0; } else if(n == 0) { return 1; } else if(map[n] > -1) { return map[n]; } else { map[n] = countWaysDP(n - 1, map) + countWaysDP(n - 2, map) + countWaysDP(n - 3, map); return map[n]; } } }