-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36.js
More file actions
22 lines (22 loc) · 671 Bytes
/
36.js
File metadata and controls
22 lines (22 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var isValidSudoku = function(board) {
let valid = [];//0-8 vertical, 9-17 block, 18 horizontal
for(let i=0;i<19;i++){
valid[i] = {};
}
for(let r=0;r<board.length;r++){
for(let c=0;c<board.length;c++){
if(board[r][c]==='.')continue;
let block = Math.floor(c/3)+Math.floor(r/3)*3;
let d = board[r][c];
if(valid[18][d]===1||valid[c][d]===1||valid[9+block][d]===1){
return false;
}else{
valid[18][d] = 1;
valid[c][d] = 1;
valid[9+block][d] = 1;
}
}
valid[18] = {};
}
return true;
};