You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
598 B
TypeScript
18 lines
598 B
TypeScript
export function isValidSudoku(board: string[][]): boolean {
|
|
const rowTable: Record<string, string[]> = {}
|
|
const colTable: Record<string, string[]> = {}
|
|
const cellTable: Record<string, string[]> = {}
|
|
|
|
for (let i = 0; i < board.length; i++) {
|
|
rowTable[i] = board[i].filter(item => item !== ".");
|
|
if (new Set(rowTable[i]).size !== rowTable[i].length) return false;
|
|
colTable[i] = board.map(item => item[i]).filter(item => item !== ".");
|
|
if (new Set(colTable[i]).size !== rowTable[i].length) return false;
|
|
}
|
|
|
|
|
|
console.log({ cellTable, rowTable, colTable })
|
|
|
|
return true
|
|
};
|