You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (x < 0 || y < 0 || x >= board.length || y >= board[0].length || board[x][y] != word.charAt(idx)) {
92
89
returnfalse;
93
90
}
94
91
95
92
chartemp = board[x][y];
96
93
board[x][y] = '#';
97
94
98
-
booleanfound =
99
-
dfs(board, x + 1, y, word, idx + 1) ||
100
-
dfs(board, x - 1, y, word, idx + 1) ||
101
-
dfs(board, x, y + 1, word, idx + 1) ||
102
-
dfs(board, x, y - 1, word, idx + 1);
95
+
booleanfound = dfs(board, x + 1, y, word, idx + 1) || dfs(board, x - 1, y, word, idx + 1) || dfs(board, x, y + 1, word, idx + 1) || dfs(board, x, y - 1, word, idx + 1);
103
96
104
97
board[x][y] = temp;
105
98
@@ -114,31 +107,28 @@ private boolean dfs(char[][] board, int x, int y, String word, int idx) {
114
107
* @param word The target word to search for in the board.
115
108
* @return True if the word exists in the board; false otherwise.
116
109
*/
117
-
// public boolean exist(char[][] board, String word) {
118
-
// this.board = board;
119
-
// this.word = word;
120
-
// for (int i = 0; i < board.length; ++i) {
121
-
// for (int j = 0; j < board[0].length; ++j) {
122
-
// if (board[i][j] == word.charAt(0)) {
123
-
// visited = new boolean[board.length][board[0].length];
124
-
// boolean exists = doDFS(i, j, 1);
125
-
// if (exists) {
126
-
// return true;
127
-
// }
128
-
// }
129
-
// }
130
-
// }
131
-
// return false;
132
-
// }
133
-
134
-
110
+
// public boolean exist(char[][] board, String word) {
111
+
// this.board = board;
112
+
// this.word = word;
113
+
// for (int i = 0; i < board.length; ++i) {
114
+
// for (int j = 0; j < board[0].length; ++j) {
115
+
// if (board[i][j] == word.charAt(0)) {
116
+
// visited = new boolean[board.length][board[0].length];
0 commit comments