/
Valid Sudoku.py
33 lines (31 loc) · 1020 Bytes
/
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
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
point = "."
for i in range(9):
row = []
column = []
square = []
for j in range(9):
element = board[i][j]
if element != point:
if element in row:
return False
else:
row.append(element)
element = board[j][i]
if element != point:
if element in column:
return False
else:
column.append(element)
element = board[i // 3 * 3 + j // 3][i % 3 * 3 + j % 3]
if element != point:
if element in square:
return False
else:
square.append(element)
return True