Skip to content

Commit e589510

Browse files
authored
Update 723-candy-crush.js
1 parent ca265f5 commit e589510

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

723-candy-crush.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,22 @@ const candyCrush = function (board) {
101101
if (val === 0) continue
102102
if (
103103
j < M - 2 &&
104-
Math.abs(board[i][j + 1]) == val &&
105-
Math.abs(board[i][j + 2]) == val
104+
Math.abs(board[i][j + 1]) === val &&
105+
Math.abs(board[i][j + 2]) === val
106106
) {
107107
found = true
108108
let ind = j
109-
while (ind < M && Math.abs(board[i][ind]) == val)
109+
while (ind < Math.min(M, j + 3) && Math.abs(board[i][ind]) === val)
110110
board[i][ind++] = -val
111111
}
112112
if (
113113
i < N - 2 &&
114-
Math.abs(board[i + 1][j]) == val &&
115-
Math.abs(board[i + 2][j]) == val
114+
Math.abs(board[i + 1][j]) === val &&
115+
Math.abs(board[i + 2][j]) === val
116116
) {
117117
found = true
118118
let ind = i
119-
while (ind < N && Math.abs(board[ind][j]) == val)
119+
while (ind < Math.min(N, i + 3) && Math.abs(board[ind][j]) === val)
120120
board[ind++][j] = -val
121121
}
122122
}

0 commit comments

Comments
 (0)