[Python Code] anyone please figure out what I am doing wrong please...


  • 0
    J

    I don't know what I am doing wrong at here... I hand draw the Sudoku and seems like the Sudoku is really not valid... because there are two 6's in one same row/column

    0_1500957229011_2017-07-24 (1).png

    my code:

    '''

    def isValidSudoku(self, board):
        
        r = []*9
        cl = []*9
        rowNum = 0
        colNum = 0
        m = []
    
        for i in range(9):
            r.append([])
            cl.append([])
    
        try:
            for j in range(9):
                m = []
                for i in range(9):
                    c = board[j][i]
                    if c == ".":
                        continue
                    row = j//3
                    col = j%3
                    rowNum = row*3+i//3
                    colNum = col*3+i%3
                    if not c in r[rowNum] and not c in m and not c in cl[colNum]:
                        r[rowNum].append(c)
                        cl[colNum].append(c)
                        m.append(c)
                    else:
                        return False  
                
        except:
            return False
        return True
    

    '''


Log in to reply
 

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