@@ -10,15 +10,15 @@ const exist = (board, word) => {
10
10
// wordList.shift()
11
11
// console.log(wordList);
12
12
13
- const expand = ( r , c , visit , wordList ) => {
14
- console . log ( `r:${ r } , c:${ c } , visit:` )
15
- console . log ( wordList )
13
+ const expand = ( r , c , visit , i ) => {
14
+ console . log ( `r:${ r } , c:${ c } , i: ${ i } , visit:` )
15
+ // console.log(wordList)
16
16
console . log ( visit )
17
17
// console.log(i)
18
18
// console.log(word.length)
19
19
// console.log(i === word.length)
20
20
21
- if ( 0 === wordList . length ) {
21
+ if ( i === word . length ) {
22
22
console . log ( ">>>>>>>> >TRUE" )
23
23
doesExist = true ;
24
24
}
@@ -33,16 +33,21 @@ const exist = (board, word) => {
33
33
return ;
34
34
}
35
35
36
- if ( wordList [ 0 ] === board [ r ] [ c ] ) {
37
- console . log ( `${ wordList [ 0 ] } vs ${ board [ r ] [ c ] } ` )
38
- visit [ r ] [ c ] = 1 ;
39
- wordList . shift ( ) ;
40
-
41
- expand ( r , c + 1 , visit , wordList ) ;
42
- expand ( r + 1 , c , visit , wordList ) ;
43
- expand ( r , c - 1 , visit , wordList ) ;
44
- expand ( r - 1 , c , visit , wordList ) ;
45
- }
36
+ if ( word [ i ] !== board [ r ] [ c ] ) return ;
37
+
38
+ console . log ( `${ word [ i ] } vs ${ board [ r ] [ c ] } ` )
39
+ visit [ r ] [ c ] = 1 ;
40
+ i ++
41
+ // wordList.shift();
42
+
43
+ // expand(r, c + 1, visit, wordList);
44
+ // expand(r + 1, c, visit, wordList);
45
+ // expand(r, c - 1, visit, wordList);
46
+ // expand(r - 1, c, visit, wordList);
47
+ expand ( r , c + 1 , visit , i ) ;
48
+ expand ( r + 1 , c , visit , i ) ;
49
+ expand ( r , c - 1 , visit , i ) ;
50
+ expand ( r - 1 , c , visit , i ) ;
46
51
}
47
52
48
53
// console.log(board)
@@ -51,8 +56,9 @@ const exist = (board, word) => {
51
56
if ( ! doesExist && word [ 0 ] === board [ r ] [ c ] ) {
52
57
console . log ( `>>>>> ${ word [ 0 ] } === ${ board [ r ] [ c ] } ` )
53
58
let visit = Array . from ( { length : board . length } , ( ) => Array . from ( { length : board [ 0 ] . length } , ( ) => 0 ) )
54
- let wordList = word . split ( "" ) ;
55
- expand ( r , c , visit , wordList ) ;
59
+ // let wordList = word.split("");
60
+ // expand(r, c, visit, wordList);
61
+ expand ( r , c , visit , 0 ) ;
56
62
}
57
63
}
58
64
}
@@ -71,11 +77,11 @@ let x = null;
71
77
// ["A", "D", "E", "E"]
72
78
// ], "ABCCED")//true
73
79
74
- // x = exist([
75
- // ["A", "B", "C", "E"],
76
- // ["S", "F", "E", "S"],
77
- // ["A", "D", "E", "E"]
78
- // ], "ABCEFSADEESE") // true
80
+ x = exist ( [
81
+ [ "A" , "B" , "C" , "E" ] ,
82
+ [ "S" , "F" , "E" , "S" ] ,
83
+ [ "A" , "D" , "E" , "E" ]
84
+ ] , "ABCEFSADEESE" ) // true
79
85
80
86
// x = exist(
81
87
// [
@@ -84,11 +90,11 @@ let x = null;
84
90
// ["A", "D", "E", "E"]
85
91
// ], "ABCB") // false
86
92
87
- x = exist (
88
- [
89
- [ "a" , "b" ] ,
90
- [ "c" , "d" ]
91
- ] , "abcd" ) // false
93
+ // x = exist(
94
+ // [
95
+ // ["a", "b"],
96
+ // ["c", "d"]
97
+ // ], "abcd") // false
92
98
93
99
// x = exist(
94
100
// [
0 commit comments