Simple to Understand Python Sol


  • 0
    C
    class Solution(object):
        def isValidSudoku(self, board):
            if self.func(board)==False:
                return False
            x=zip(board[0],board[1],board[2],board[3],board[4],board[5],board[6],board[7],board[8])
            if self.func(x)==False:
                return False
            for h in range(0,8,3):
                combine=[]
                x,y,z = board[h], board[h+1], board[h+2]
                q=x[:3]+y[:3]+z[:3]
                combine.append(q)
                r=x[3:6]+y[3:6]+z[3:6]
                combine.append(r)
                s=x[6:]+y[6:]+z[6:]
                combine.append(s)
                if self.func(combine)==False:
                    return False
            return True
            
        def func(self,itera):
          for s in itera:
            count = collections.Counter(s)
            for d in count.keys():
              if d!='.' and count[d]>1:
                return False
    

Log in to reply
 

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