-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path036.py
More file actions
41 lines (38 loc) · 841 Bytes
/
036.py
File metadata and controls
41 lines (38 loc) · 841 Bytes
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
33
34
35
36
37
38
39
40
41
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
# Check rows
for r in board:
d = set()
for ch in r:
if ch == '.':
continue
if ch in d:
return False
d.add(ch)
# Check cols
for i in xrange(9):
d = set()
for j in xrange(9):
ch = board[j][i]
if ch == '.':
continue
if ch in d:
return False
d.add(ch)
# Check grid
for i in xrange(3):
for j in xrange(3):
d = set()
for ii in xrange(3):
for jj in xrange(3):
ch = board[i * 3 + ii][j * 3 + jj]
if ch == '.':
continue
if ch in d:
return False
d.add(ch)
return True