Test case might be wrong with Python


  • 0
    D

    There is no list obj that I pass to isvalid function, and my local shell returns True for this case. But got this in OJ:

    Runtime Error Message: Line 34: AttributeError: 'list' object has no attribute 'replace'
    Last executed input: [".87654321","2........","3........","4........","5........","6........","7........","8........","9........"]

    class Solution:
    # @param board, a 9x9 2D array
    # @return a boolean
    def isValidSudoku(self, board):
        for row in board:
            if not isvalid(row):
                return False
        rotated = []
        for i in xrange(9):
            p = ''
            for r in board:
                p += r[i]
            rotated.append(p)
        for row in rotated:
            if not isvalid(row):
                return False
        m = 3
        while m < 10:
            new1 = ''
            new2 = ''
            new3 = ''
            for r in board[m:m+3]:
                new1+= r[:3]
                new2 += r[3:6]
                new3 += r[6:9]
            for new in [new1, new2, new3]:
                if not isvalid(new):
                    return False
    
            m += 3
        return True
    
    def isvalid(astr):
         astr = astr.replace('.', '')
         alist = sorted(astr.split())
         for i in xrange(len(alist)-1):
             if alist[i] == alist[i+1]:
                  return False
         return True

  • 0
    H

    The error messge says:
    it tried to getattribute on a list object but cannot find replace3 method.
    Are you using python 3?


  • 0
    D

    I'm using python 2.7 and I do think this is a version issue, a sliced string is a string in python 2.7.


Log in to reply
 

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