8000 Merge pull request #14 from Tahirc1/Tahirc1-update-36 · Tahirc1/LeetcodeJs@ad8ed00 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad8ed00

Browse files
authored
Merge pull request #14 from Tahirc1/Tahirc1-update-36
Update 36. Valid Sudoku.js
2 parents 4cc5d18 + f778147 commit ad8ed00

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

31-40/36. Valid Sudoku.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
var isValidSudoku = function(board) {
2+
// create variable to store row , col and box values
23
let row = []
34
let col = []
45
let box = []
6+
// loop i over 0-8
57
for (let i = 0; i <= 8; i++){
8+
// loop j over 0-8
69
for (let j = 0; j <= 8; j++){
10+
// this will help us get position of each cell from board
711
let IndI = 3*Math.floor(i/3) + Math.floor(j/3)
812
let IndJ = 3*(i % 3) + (j % 3)
13+
// check if value is already in row , col or box and return false
914
if (row.indexOf(board[i][j]) != -1 ){return false}
1015
if (col.indexOf(board[j][i]) != -1 ){return false}
1116
if (box.indexOf(board[IndI][IndJ]) != -1){return false}
12-
17+
// if not then add value to row , col and box
1318
if(board[i][j] != '.'){row.push(board[i][j])}
1419
if(board[j][i] != '.'){col.push(board[j][i])}
1520
if(board[IndI][IndJ] != '.'){box.push(board[IndI][IndJ])}
1621
}
22+
// reset row , col and box array
1723
row = []
1824
col = []
1925
box = []
2026
}
2127

2228
return true
23-
}
29+
}

0 commit comments

Comments
 (0)
0