deno.land / x / masx200_leetcode_test@10.6.5 / valid-sudoku / index.ts
1234567891011121314151617181920212223242526272829303132333435/* * @lc app=leetcode.cn id=36 lang=typescript * * [36] 有效的数独 */
// @lc code=startexport default function isValidSudoku(board: string[][]): boolean { const rows = new Array(9).fill(0).map(() => new Set<string>()); const columns = new Array(9).fill(0).map(() => new Set<string>()); const subboxes = new Array(3) .fill(0) .map(() => new Array(3).fill(0).map(() => new Set<string>()));
for (let i = 0; i < 9; i++) { for (let j = 0; j < 9; j++) { const c = board[i][j]; if (c !== ".") { if ( rows[i].has(c) || columns[j].has(c) || subboxes[Math.floor(i / 3)][Math.floor(j / 3)].has(c) ) { return false; } rows[i].add(c); columns[j].add(c); subboxes[Math.floor(i / 3)][Math.floor(j / 3)].add(c); } } } return true;}// @lc code=end
Version Info