Method
dfs
(char[][] board, String word, int i, int j, int index)
Source from the content-addressed store, hash-verified
| 18 | } |
| 19 | |
| 20 | private boolean dfs(char[][] board, String word, int i, int j, int index) { |
| 21 | if (index == word.length()) { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | if (i < 0 || i >= board.length || j < 0 || j >= board[0].length || |
| 26 | visited[i][j] || board[i][j] != word.charAt(index)) { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | visited[i][j] = true; |
| 31 | |
| 32 | for (int[] dir : directions) { |
| 33 | if (dfs(board, word, i + dir[0], j + dir[1], index + 1)) { |
| 34 | return true; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | visited[i][j] = false; |
| 39 | return false; |
| 40 | } |
| 41 | } |
Tested by
no test coverage detected