forked from walkccc/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0036.py
More file actions
28 lines (24 loc) · 1.01 KB
/
0036.py
File metadata and controls
28 lines (24 loc) · 1.01 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
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
def isValidRow(board: List[List[str]]) -> bool:
for row in board:
if isValid(row) == False:
return False
return True
def isValidCol(board: List[List[str]]) -> bool:
for col in zip(*board):
if isValid(col) == False:
return False
return True
def isValidSquare(board: List[List[str]]) -> bool:
for i in (0, 3, 6):
for j in (0, 3, 6):
square = [board[x][y]
for x in range(i, i + 3) for y in range(j, j + 3)]
if isValid(square) == False:
return False
return True
def isValid(list: List[str]) -> bool:
res = [i for i in list if i != '.']
return len(res) == len(set(res))
return isValidRow(board) and isValidCol(board) and isValidSquare(board)