Introduced
The Sudoku may only be populated with partial numbers, in which the missing digits are used. Said.
Attention matters
A valid Sudoku (only partially populated) is not necessarily solvable. We just need to make the padding space valid.
Thoughts of disintegration
The Sudoku is preprocessed according to rows, columns, and blocks, and then separately judged to be legitimate.
Using Python's expression derivation, anonymous functions and all
functions can be easily processed.
Code
Class Solution:
# @param board, a 9x9 2D array
# @return A Boolean
def isvalidsudoku (self, Board):
rows = [List (lst[::]) for LST in board]
columns = [[Lst[idx] for LST in board] for IDX in range (9)]
blocks_origin = [Board[row][column] for x in [[0, 1, 2], [ 3, 4, 5], [6, 7, 8]] for y in [[0, 1, 2], [3, 4, 5], [6, 7, 8]] for row in x for column in Y] # using some techniques to store data directly in chunks
blocks = [[Blocks_origin[row * 9 + column] for column in range (9)] for row in range (9)]
check = Lambda Lst:all ([Lst.count (x) = = 1 for x in LST if x!= '. '] # Determine if a record (nine digits in one way or another) is legal return all
([Check (x) for style in (rows, columns, blocks) for x in style]) # one step down
Summary
Can not use the circulation body as far as possible without circulation body, the above is the entire content of this article, I hope for everyone's study and work can help, if there is doubt you can message exchange.