Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. class Solution(object):
  2.     def isValidSudoku(self, a):
  3.         rows = [set() for _ in range(9)]
  4.         cols = [set() for _ in range(9)]
  5.         grids = [set() for _ in range(9)]
  6.        
  7.         for i in range(9):
  8.             for j in range(9):
  9.                 if a[i][j] == '.': continue
  10.                 g_no = ((i//3) * 3) + j//3
  11.                 if a[i][j] in rows[i] or a[i][j] in cols[j] or a[i][j] in grids[g_no]: return False
  12.                 rows[i].add(a[i][j])
  13.                 cols[j].add(a[i][j])
  14.                 grids[g_no].add(a[i][j])
  15.         return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement