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(pos==word.length())//if position of word is equal to length of word that means word is present in array
28
28
returntrue;
29
29
30
30
intM=board.length, N=board[0].length;
31
-
if(i < 0 || i >= M || j < 0 || j >= N || board[i][j]!=word.charAt(pos) || board[i][j]=='#') //comparing the required conditions
31
+
if(i < 0 || i >= M || j < 0 || j >= N || board[i][j]!=word.charAt(pos) || board[i][j]=='#') //checking the necessary condition to find out whether word exists or not
32
32
returnfalse;
33
33
34
34
chardup=board[i][j];
35
35
board[i][j]='#';
36
36
37
-
booleanans = dfs(board, i + 1, j, word, pos + 1) ||
38
-
dfs(board, i - 1, j, word, pos + 1) ||
39
-
dfs(board, i, j + 1, word, pos + 1) ||
40
-
dfs(board, i, j - 1, word, pos + 1);
37
+
booleanans = dfs(board, i + 1, j, word, pos + 1) ||//traversing one letter right
38
+
dfs(board, i - 1, j, word, pos + 1) ||////traversing one letter left
39
+
dfs(board, i, j + 1, word, pos + 1) ||//traversing one letter up
40
+
dfs(board, i, j - 1, word, pos + 1);////traversing one letter down
0 commit comments