Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.code
The Sudoku board could be partially filled, where empty cells are filled with the character '.'.it
A partially filled sudoku which is valid.io
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.class
把三個都判斷下就完了date
class Solution: # @param board, a 9x9 2D array # @return a boolean def isValidSudoku(self, board): #row for i in range(9): vis = [False] * 9 for j in range(9): if board[i][j] == '.': continue if vis[int(board[i][j])-1] == True: return False else: vis[int(board[i][j])-1] = True #colum for i in range(9): vis = [False] * 9 for j in range(9): if board[j][i] == '.': continue if vis[int(board[j][i])-1] == True: return False else: vis[int(board[j][i])-1] = True #block for i in range(0,9,3): for j in range(0,9,3): vis = [False] * 9 for k in range(i,3+i): for l in range(j,3+j): if board[k][l] == '.': continue if vis[int(board[k][l])-1] == True: return False else: vis[int(board[k][l])-1] = True return True