forked from zzxboy1/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid_Sudoku.js
More file actions
28 lines (27 loc) · 784 Bytes
/
Valid_Sudoku.js
File metadata and controls
28 lines (27 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @param {character[][]} board
* @return {boolean}
*/
var isValidSudoku = function(board) {
var a = new Array(9),
b = new Array(9),
c = new Array(9);
for (var k = 0; k < 9; k++) {
a[k] = new Array(9);
b[k] = new Array(9);
c[k] = new Array(9);
}
for (var i = 0; i < 9; i++) {
for (var j = 0; j < 9; j++) {
var temp = board[i][j];
if (temp === ".") {
continue;
}
if (a[i][temp - 1] || b[temp - 1][j] || c[Math.floor(i / 3) * 3 + Math.floor(j / 3)][temp - 1]) {
return false;
}
a[i][temp - 1] = b[temp - 1][j] = c[Math.floor(i / 3) * 3 + Math.floor(j / 3)][temp - 1] = true;
}
}
return true;
};