Solved for all test cases

This commit is contained in:
Jacob Delgado 2023-09-19 23:47:10 -07:00
parent 580f34ebc8
commit 852af63a7e

View File

@ -3,14 +3,22 @@ def isValidSudoku(board):
:type board: List[List[str]]
:rtype: bool
"""
temp = []
for x in range(len(board)):
for y in range(len(board[x])):
if y not in temp:
temp.append(board[x])
else:
rows = [set() for x in range(9)]
columns = [set() for x in range(9)]
squares = [[set() for x in range(3)] for y in range(3)]
for x in range(9):
for y in range(9):
cell_value = board[x][y]
if cell_value == ".":
continue
if cell_value in rows[x] or cell_value in columns[y] or cell_value in squares[x//3][y//3]:
return False
temp = temp /3*3
rows[x].add(cell_value)
columns[y].add(cell_value)
squares[x//3][y//3].add(cell_value)
return True