We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java 1D Array (Part 2)
Java 1D Array (Part 2)
Sort by
recency
|
627 Discussions
|
Please Login in order to post a comment
public static boolean canWin(int leap, int[] game) { return canWinHelper(leap, game, 0); }
// Helper method to recursively check if the game can be won private static boolean canWinHelper(int leap, int[] game, int pos) { // Base cases if (pos < 0 || game[pos] == 1) return false; // Out of bounds or already visited if (pos >= game.length - 1 || pos + leap >= game.length) return true; // Win condition
}
import java.util.*;
public class Solution {
}
reposting a solution from @kdubey2181, that I think is the most elegant and simple way to solve this problem.
whats wrong with my iterative approach can anyone point out?