-
Notifications
You must be signed in to change notification settings - Fork 0
/
36. Valid Sudoku.py
35 lines (33 loc) · 1.13 KB
/
36. Valid Sudoku.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
31
32
33
34
35
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
for i in range(0,len(board)):
for j in range(0,len(board[i])):
if board[i][j] == '.':
continue
for l in range(0,len(board)):
if l == i:
continue
if board[l][j] == board[i][j]:
return False
for k in range(0,len(board[i])):
if k == j:
continue
if board[i][k] == board[i][j]:
return False
row = i / 3
col = j / 3
for r in range(row * 3,row * 3 + 3):
for c in range(col * 3,col * 3 + 3):
if r == i and c == j:
continue
if board[r][c] == board[i][j]:
return False
return True
if __name__ == "__main__":
solution = Solution()
re = solution.isValidSudoku()
print re