Source of the topic:
https://leetcode.com/problems/sudoku-solver/
Test Instructions Analysis:
This topic is the evolutionary version of the previous question. Fill out a Sudoku.
Topic Ideas:
This problem is solved directly with DFS violence. Please fill in the "*" with (1-9) directly. The complexity of time is relatively high. Note that the title requires no return value, so write a separate function to determine whether the fill can be filled after the number of fills.
Code (Python):
1 classsolution (object):2 defIsvalue (self,board,x,y):3 #Column Meets4 forIinchRange (9):5 ifI! = X andBoard[i][y] = =Board[x][y]:6 returnFalse7 forJinchRange (9):8 ifJ! = Y andBOARD[X][J] = =Board[x][y]:9 returnFalseTenJ + = 1 Onem = * * (x//3); n = * * (Y//3) A forIinchRange (3): - forJinchRange (3): - if(i + M! = XorJ + N! = y) andBoard[i + m][j + N] = =Board[x][y]: the returnFalse - returnTrue - defDFS (self,board): - forIinchRange (9): + forJinchRange (9): - ifBOARD[I][J] = ='.': + forKinch '123456789': ABOARD[I][J] =k at ifSelf.isvalue (BOARD,I,J) andSelf.dfs (board): - returnTrue -BOARD[I][J] ='.' - returnFalse - returnTrue - in defSolvesudoku (self, Board): - """ to : Type BOARD:LIST[LIST[STR]] + : Rtype:void does not return anything, modify board In-place instead. - """ the Self.dfs (board) *
View Code
Reprint Please specify source: http://www.cnblogs.com/chruny/p/4926274.html
[Leetcode] (python): 037-sudoku Solver