private void setWordsByCell(int i, int j) { wordsFromCell = new Bag<>(); marked = new boolean[M][N]; wordTo = new String[M][N]; String letter = board.getLetter(i, j) + ""; if (Objects.equals(letter, "Q")) { wordTo[i][j] = "QU"; } else { wordTo[i][j] = letter; } dfs(i, j); }
private void dfs(int i, int j) { marked[i][j] = true; if (wordTo[i][j].length() > 2 && dict.contains(wordTo[i][j])) { wordsFromCell.add(wordTo[i][j]); } if (dict.keysWithPrefix(wordTo[i][j]).iterator().hasNext()) { Iterable<int[]> adj = adj(i, j); for (int[] a : adj) { if (!marked[a[0]][a[1]]) { String letter = board.getLetter(a[0], a[1]) + ""; if (Objects.equals(letter, "Q")) { wordTo[a[0]][a[1]] = wordTo[i][j] + "QU"; } else { wordTo[a[0]][a[1]] = wordTo[i][j] + letter; } dfs(a[0], a[1]); } } } marked[i][j] = false; }