update 36
This commit is contained in:
parent
a09cbb3dc4
commit
a46d328298
23
leetcode/36.py
Normal file
23
leetcode/36.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Valid Sudoku
|
||||
|
||||
|
||||
class Solution:
|
||||
def isValidSuduku(self, board: list[list[int]]) -> bool:
|
||||
rows = [set() for _ in range(9)]
|
||||
cols = [set() for _ in range(9)]
|
||||
boxes = [set() for _ in range(9)]
|
||||
|
||||
for i in range(9):
|
||||
for j in range(9):
|
||||
num = board[i][j]
|
||||
if num != ".":
|
||||
box_index = (i // 3) * 3 + j // 3
|
||||
|
||||
if num in rows[i] or num in cols[j] or num in boxes[box_index]:
|
||||
return False
|
||||
|
||||
rows[i].add(num)
|
||||
cols[j].add(num)
|
||||
boxes[box_index].add(num)
|
||||
|
||||
return True
|
Loading…
x
Reference in New Issue
Block a user