You are viewing a single comment's thread. Return to all comments →
Buttom up approach using stack is just sweet!
public static boolean canWin(int leap, int[] game) { int n = game.length; Stack<Integer> potentialIndexes = new Stack<>(); potentialIndexes.push(0); while (!potentialIndexes.isEmpty()) { int i = potentialIndexes.pop(); if (i >= n) return true; if (i < 0 || game[i] == 1) continue; game[i] = 1; potentialIndexes.push(i+1); potentialIndexes.push(i-1); potentialIndexes.push(i+leap); } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java 1D Array (Part 2)
You are viewing a single comment's thread. Return to all comments →
Buttom up approach using stack is just sweet!