A Python solution is here

  • 0
    class Solution:
        def solveSudoku(self, board):
            :type board: List[List[str]]
            :rtype: void Do not return anything, modify board in-place instead.
            for i, grid in enumerate(board):
                for j, value in enumerate(grid):
                    if value == '.':
                        cands = self.isValid(board, i, j)
                        if len(cands) == 1:
                            board[i][j] = cands[0]
        def isValid(self, board, grid_pos, elem_pos):
            list = ['1','2','3','4','5','6','7','8','9']
            cols = []
            rows = []
            for i, grid in enumerate(board):
                if i%3 == grid_pos%3 or i//3 == grid_pos//3:
                    for j, elem in enumerate(grid): 
                        if i%3 == grid_pos%3 and j%3 == elem_pos%3 and elem != '.':
                        if i//3 == grid_pos//3 and j//3 == elem_pos//3 and elem != '.':
            cands = []
            for element in list:
                if element not in board[grid_pos] and element not in rows and element not in cols:
            return cands

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.