private long getPaths(Position p) { return (p.hasDown() ? getPaths(p.getDown()) : 0) + (p.hasRight() ? getPaths(p.getRight()) : 0) + ((p.getRow() == board.length - 1) && (p.getColumn() == board.length -1) ? 1 : 0); }
private long getPaths(Position p, long count) { if (p.hasDown()) { getPaths(p.getDown(), count); } if (p.hasRight()) { getPaths(p.getRight(), count); } if ((p.getRow() == board.length - 1) && (p.getColumn() == board.length - 1)) { count++; } return count; }
private long getPaths(Position p) { return (p.hasDown() ? getPaths(p.getDown()) : 0) + (p.hasRight() ? getPaths(p.getRight()) : 0) + ((p.getRow() == board.length - 1) && (p.getColumn() == board.length -1) ? 1 : 0); }
public long getNumberOfPaths() { return getPaths(new Position(0,0)); //2D array of Positions } private long getPaths(Position p) { long result= 0; if (p.hasDown()) { result+= getPaths(p.getDown()); } if (p.hasRight()) { result+= getPaths(p.getRight()); } if ((p.getRow() == board.length - 1) && (p.getColumn() == board.length -1)) { result+= 1; } return result; }