-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvalid-sudoku.py
32 lines (27 loc) · 949 Bytes
/
valid-sudoku.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
https://leetcode.com/problems/valid-sudoku
"""
__author__ = "prakashsellathurai"
__copyright__ = "Copyright 2021"
__version__ = "1.0.1"
__email__ = "[email protected]"
class Solution:
@staticmethod
def isValidSudoku(board: List[List[str]]) -> bool:
boardMap = collections.defaultdict(list)
for x in range(9):
for y in range(9):
char = board[x][y]
if char != ".":
if char in boardMap:
for pos in boardMap[char]:
if (
(pos[0] == x)
or (pos[1] == y)
or (pos[0] // 3 == x // 3 and pos[1] // 3 == y // 3)
):
return False
boardMap[char].append((x, y))
return True