标签:
class Solution: # @param {character[][]} board # @return {void} Do not return anything, modify board in-place instead. def solveSudoku(self, board): def check( x, y): temp = board[x][y]; board[x][y] = '.' for i in xrange(9): if board[i][y] == temp: return False for j in xrange(9): if board[x][j] == temp: return False for i in xrange(3): for j in xrange(3): if board[(x/3)*3 + i][(y/3)*3 + j] == temp: return False board[x][y] = temp return True def dfs(board): for i in xrange(9): for j in xrange(9): if board[i][j] == '.': for k in '123456789': board[i][j] = k if check(i, j) and dfs(board): return True board[i][j] = '.' return False return True dfs(board)
标签:
原文地址:http://blog.csdn.net/andrew9tech/article/details/46602805