Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def isValidSudoku(self, a):
- rows = [set() for _ in range(9)]
- cols = [set() for _ in range(9)]
- grids = [set() for _ in range(9)]
- for i in range(9):
- for j in range(9):
- if a[i][j] == '.': continue
- g_no = ((i//3) * 3) + j//3
- if a[i][j] in rows[i] or a[i][j] in cols[j] or a[i][j] in grids[g_no]: return False
- rows[i].add(a[i][j])
- cols[j].add(a[i][j])
- grids[g_no].add(a[i][j])
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement