-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0036.py
More file actions
25 lines (19 loc) · 786 Bytes
/
0036.py
File metadata and controls
25 lines (19 loc) · 786 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
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
grids = defaultdict(set)
columns = defaultdict(set)
for r in range(len(board)):
used = set()
for c in range(len(board[r])):
if board[r][c] != '.':
if board[r][c] in used:
return False
if board[r][c] in columns[c]:
return False
node = grids[(3 * (r // 3)) + (c // 3)]
if board[r][c] in node:
return False
used.add(board[r][c])
columns[c].add(board[r][c])
node.add(board[r][c])
return True