-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36.py
30 lines (27 loc) · 863 Bytes
/
36.py
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
29
30
def isValidSudoku(board):
# Check rows
for i in range(9):
row = set()
for j in range(9):
if board[i][j] != ".":
if board[i][j] in row:
return False
row.add(board[i][j])
# Check columns
for j in range(9):
col = set()
for i in range(9):
if board[i][j] != ".":
if board[i][j] in col:
return False
col.add(board[i][j])
# Check sub-boxes
for box in range(9):
sub_box = set()
for i in range(box // 3 * 3, box // 3 * 3 + 3):
for j in range(box % 3 * 3, box % 3 * 3 + 3):
if board[i][j] != ".":
if board[i][j] in sub_box:
return False
sub_box.add(board[i][j])
return True