Python problem with dictionary(interesting different behavior with C++)


  • 0
    J
    class Solution(object):
        def isValidSudoku(self, board):
            """
            :type board: List[List[str]]
            :rtype: bool
            """
            dictR = [{}]*9
            dictC = [{}]*9
            dict = [{}]*9
            
            for i in xrange(9):
                for j in xrange(9):
                    if board[i][j] != '.':
                    
                        if (board[i][j] in dictR[i]) | (board[i][j] in dictC[j]) | (board[i][j] in dict[(i//3) * 3 + (j//3)]):
                            return False
                        else:
                            dictR[i][board[i][j]] = 1
                            dictC[j][board[i][j]] = 1
                            dict[(i//3) * 3 + (j//3)][board[i][j]] = 1
                    
            return True;        
                    
    

    The code is not working.
    I am new to Python. I wonder what is wrong with this code.


  • 0
    J

    I used the same method as I did with C++. There must be some semantic problem.


Log in to reply
 

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