| 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; |