这个解法告诉我们读题要精确,且例证了多维数组的重要性。
# Sudoku [http://en.wikipedia.org/wiki/Sudoku]
# A valid sudoku square satisfies these
# two properties:# 1. Each column of the square contains each of the whole numbers from 1 to n exactly once.
# 2. Each row of the square contains each of the whole numbers from 1 to n exactly once.
# You may assume the the input is square and contains at least one row and column.
def check_sudoku(m):
n = len(m) # set the size of the matrix for x in range(n): row,col = [],[] # use lists so I can use "in" for y in range(n): row.append(m[x][y]) # build row and column list col.append(m[y][x]) for i in range(1,n+1): # count from 1 to n if (i) not in col or (i) not in row: return False # Fail if integer is missing return True