deno.land / x / masx200_leetcode_test@10.6.5 / valid-sudoku / index.ts

نووسراو ببینە
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
29
30
31
32
33
34
35
/* * @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
masx200_leetcode_test

Version Info

Tagged at
2 years ago