-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36_Valid_Sudoku.py
More file actions
33 lines (30 loc) · 1.03 KB
/
Copy path36_Valid_Sudoku.py
File metadata and controls
33 lines (30 loc) · 1.03 KB
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
31
32
33
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
for i in range(0, 9):
hashSet = set()
for j in range(0, 9):
if board[i][j] != "." and board[i][j] in hashSet:
return False
else:
hashSet.add(board[i][j])
for j in range(0, 9):
hashSet = set()
for i in range(0, 9):
if board[i][j] != "." and board[i][j] in hashSet:
return False
else:
hashSet.add(board[i][j])
i = 0
while(i < 9):
j = 0
while(j < 9):
hashSet = set()
for k in range(i, i + 3):
for l in range(j, j + 3):
if board[k][l] != "." and board[k][l] in hashSet:
return False
else:
hashSet.add(board[k][l])
j += 3
i += 3
return True