Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f778147

Browse files
authored
Update 36. Valid Sudoku.js
adding explanation to problem 36
1 parent 4cc5d18 commit f778147

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)

AltStyle によって変換されたページ (->オリジナル) /