https://leetcode.cn/problems/valid-sudoku/submissions/576211089/?envType=study-plan-v2&envId=top-interview-150
脑筋急转弯题
var isValidSudoku = function (board) {
for (let index = 0; index < board.length; index++) {
const hasNum = new Array(10).fill(false);
for (let indey = 0; indey < board[0].length; indey++) {
const char = board[index][indey];
if (char !== ".") {
if (hasNum[char]) {
return false;
}
hasNum[char] = true;
}
}
}
//竖排
for (let index = 0; index < board[0].length; index++) {
const hasNum = new Array(10).fill(false);
for (let indey = 0; indey < board.length; indey++) {
const char = board[indey][index];
if(char=='5'){
debugger
}
if (char !== ".") {
if (hasNum[char]) {
return false;
}
hasNum[char] = true;
}
}
}
for (let x = 0; x < board[0].length / 3; x++) {
for (let y = 0; y < board.length / 3; y++) {
const hasNum = new Array(10).fill(false);
for (let index = 0; index < 3; index++) {
for (let indey = 0; indey < 3; indey++) {
const char = board[x * 3 + index][y * 3 + indey];
if (char !== ".") {
if (hasNum[char]) {
return false;
}
hasNum[char] = true;
}
}
}
}
}
return true;
};