We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bf1ed65 commit 336cae4Copy full SHA for 336cae4
Algorithms/Medium/36_ValidSudoku/Solution.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def isValidSudoku(self, board: List[List[str]]) -> bool:
3
+ rows = collections.defaultdict(set)
4
+ cols = collections.defaultdict(set)
5
+ sqrs = collections.defaultdict(set)
6
+
7
+ for i in range(9):
8
+ for j in range(9):
9
+ if board[i][j] == ".":
10
+ continue
11
12
+ if (board[i][j] in rows[i] or
13
+ board[i][j] in cols[j] or
14
+ board[i][j] in sqrs[(i // 3, j // 3)]):
15
+ return False
16
17
+ rows[i].add(board[i][j])
18
+ cols[j].add(board[i][j])
19
+ sqrs[(i // 3, j // 3)].add(board[i][j])
20
21
+ return True
0 commit comments