Python Code


  • 0
    B
    class Solution(object):
        def isValidSudoku(self, board):        
            result = {}
            for row_index, row in enumerate(board):
                for col_index, digit in enumerate(row):
                    if digit != '.':
                        positions = result.get(digit)
                        if not positions:
                            positions = [[],[],[]] 
                            result[digit] = positions
                        sector = (ceil(col_index/3), ceil(row_index/3))
                        if row_index in positions[0] or col_index in positions[1] or sector in positions[2]:
                            return False
                        positions[0].append(row_index)
                        positions[1].append(col_index)
                        positions[2].append(sector)
    
            return True
    

    My simple python solution


Log in to reply
 

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