版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22795513/article/details/80636525
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
for i in xrange(9):
hang = board[i]
lie = []
for j in range(9):
lie.append(board[j][i])
for m in hang:
if hang.count(m)>1 and m!='.':
return False
for n in lie:
if lie.count(n)>1 and n!='.':
return False
for j in xrange(9):
if i%3==0 and j%3==0:
small = []
for p in range(i,i+3):
for q in range(j,j+3):
if board[p][q] != '.':
small.append(board[p][q])
if len(small) != len(list(set(small))):
print i,j,p,q
return False
return True