Skip to content

Commit

Permalink
Updated 1 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
RodneyShag committed Jun 30, 2019
1 parent 2dad744 commit f2b9e39
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Java/Data Structures/Java 1D Array (Part 2)/Solution.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
// Github: github.com/RodneyShag

public static boolean canWin(int leap, int[] game) {
if (game == null) {
return false;
}
return isSolvable(leap, game, 0);
}

private static boolean isSolvable(int leap, int[] game, int i) {
/* Base Cases */
if (i < 0 || game[i] == 1) {
return false;
} else if (i + 1 >= game.length || i + leap >= game.length) {
// Base Cases
if (i >= game.length) {
return true;
} else if (i < 0 || game[i] == 1) {
return false;
}

game[i] = 1; // marks as visited

/* Recursive Cases (Tries +m first to try to finish game quickly) */
// Recursive Cases (Tries +m first to try to finish game quickly)
return isSolvable(leap, game, i + leap)
|| isSolvable(leap, game, i + 1)
|| isSolvable(leap, game, i - 1);
Expand Down

0 comments on commit f2b9e39

Please sign in to comment.