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

Method getPath

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainMethod · 0.95

Calls 2

isFreeMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected