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

Method getPath

java/Chapter 9/Question9_2/QuestionDP.java:21–37  ·  view source on GitHub ↗
(int x, int y, ArrayList<Point> path)

Source from the content-addressed store, hash-verified

19 }
20
21 public static boolean getPath(int x, int y, ArrayList<Point> path) {
22 // If out of bounds or not available, return.
23 if (y < 0 || x < 0 || !isFree(x, y)) {
24 return false;
25 }
26
27 boolean isAtOrigin = (x == 0) && (y == 0);
28
29 // If there's a path from the start to my current location, add my location.
30 if (isAtOrigin || getPath(x, y - 1, path) || getPath(x - 1, y, path)) {
31 Point p = new Point(x, y);
32 path.add(p);
33 return true;
34 }
35
36 return false;
37 }
38
39 public static boolean getPath(int x, int y, ArrayList<Point> path, Hashtable<Point, Boolean> cache) {
40 /* If out of bounds or not available, return.*/

Callers 1

mainMethod · 0.95

Calls 4

isFreeMethod · 0.95
putMethod · 0.80
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected