valid_suduko
valid_suduko.py 源码
from typing import List
# 有效的数独
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
hor, ver, grid = [[False] * 9 for _ in range(9)], [[False] * 9 for _ in range(9)], [[False] * 9 for _ in range(9)]
for i in range(9):
for j in range(9):
if board[i][j] != '.':
k = int(board[i][j]) - 1
grid_idx = (i // 3) * 3 + j // 3
if hor[i][k] or ver[j][k] or grid[grid_idx][k]:
return False
hor[i][k], ver[j][k], grid[grid_idx][k] = True, True, True
return True
你可能感兴趣的文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦