-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_036_ValidSudoku.py
More file actions
28 lines (23 loc) · 1017 Bytes
/
_036_ValidSudoku.py
File metadata and controls
28 lines (23 loc) · 1017 Bytes
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
#-----------------------------------------------------------------------------
# Runtime: 44ms
# Memory Usage:
# Link:
#-----------------------------------------------------------------------------
import copy
class Solution:
def isValidSudoku(self, board) -> bool:
colUsed = [[False for x in range(9)] for y in range(9)]
rowUsed = [[False for x in range(9)] for y in range(9)]
squareUsed = [[False for x in range(9)] for y in range(9)]
for row in range(9):
for column in range(9):
if not board[row][column].isdigit():
continue
squareId = (row // 3) * 3 + column // 3
value = int(board[row][column]) - 1
if colUsed[column][value] or rowUsed[row][value] or squareUsed[squareId][value]:
return False
colUsed[column][value] = True
rowUsed[row][value] = True
squareUsed[squareId][value] = True
return True