MCPcopy Create free account
hub / github.com/careercup/ctci / countWaysDP

Method countWaysDP

java/Chapter 9/Question9_1/Question.java:5–18  ·  view source on GitHub ↗
(int n, int[] map)

Source from the content-addressed store, hash-verified

3public class Question {
4
5 public static int countWaysDP(int n, int[] map) {
6 if (n < 0) {
7 return 0;
8 } else if (n == 0) {
9 return 1;
10 } else if (map[n] > -1) {
11 return map[n];
12 } else {
13 map[n] = countWaysDP(n - 1, map) +
14 countWaysDP(n - 2, map) +
15 countWaysDP(n - 3, map);
16 return map[n];
17 }
18 }
19
20 public static int countWaysRecursive(int n) {
21 if (n < 0) {

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected