-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid Sudoku.py
More file actions
47 lines (39 loc) · 1.21 KB
/
Copy pathValid Sudoku.py
File metadata and controls
47 lines (39 loc) · 1.21 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
__author__ = 'Martin'
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
for i in range(9):
for j in range(9):
if board[i][j] == '.':
continue
elif self.isValidCell(i, j, board) is False:
return False
return True
def isValidCell(self, x, y, board):
for i in range(9):
if y == i:
continue
else:
if board[x][y] == board[x][i]:
return False
for i in range(9):
if x == i:
continue
else:
if board[x][y] == board[i][y]:
return False
m = int(x / 3) * 3
n = int(y / 3) * 3
for i in range(3):
for j in range(3):
if x == m+i and y == n+j:
continue
elif board[x][y] == board[m+i][n+j]:
return False
return True
s = Solution()
a = ["..4...63.",".........","5......9.","...56....","4.3.....1","...7.....","...5.....",".........","........."]
print(s.isValidSudoku(a))