Solved for all test cases
This commit is contained in:
parent
580f34ebc8
commit
852af63a7e
@ -3,14 +3,22 @@ def isValidSudoku(board):
|
|||||||
:type board: List[List[str]]
|
:type board: List[List[str]]
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
temp = []
|
rows = [set() for x in range(9)]
|
||||||
for x in range(len(board)):
|
columns = [set() for x in range(9)]
|
||||||
for y in range(len(board[x])):
|
squares = [[set() for x in range(3)] for y in range(3)]
|
||||||
if y not in temp:
|
|
||||||
temp.append(board[x])
|
for x in range(9):
|
||||||
else:
|
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
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user