Skip to content

Commit 7a21f77

Browse files
committed
💀 [79] ???
1 parent 626f51f commit 7a21f77

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

79/my_solution.js

+32-26
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const exist = (board, word) => {
1010
// wordList.shift()
1111
// console.log(wordList);
1212

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)
1616
console.log(visit)
1717
// console.log(i)
1818
// console.log(word.length)
1919
// console.log(i === word.length)
2020

21-
if (0 === wordList.length) {
21+
if (i === word.length) {
2222
console.log(">>>>>>>> >TRUE")
2323
doesExist = true;
2424
}
@@ -33,16 +33,21 @@ const exist = (board, word) => {
3333
return;
3434
}
3535

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);
4651
}
4752

4853
// console.log(board)
@@ -51,8 +56,9 @@ const exist = (board, word) => {
5156
if (!doesExist && word[0] === board[r][c]) {
5257
console.log(`>>>>> ${word[0]} === ${board[r][c]}`)
5358
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);
5662
}
5763
}
5864
}
@@ -71,11 +77,11 @@ let x = null;
7177
// ["A", "D", "E", "E"]
7278
// ], "ABCCED")//true
7379

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
7985

8086
// x = exist(
8187
// [
@@ -84,11 +90,11 @@ let x = null;
8490
// ["A", "D", "E", "E"]
8591
// ], "ABCB") // false
8692

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
9298

9399
// x = exist(
94100
// [

0 commit comments

Comments
 (0)