-
Notifications
You must be signed in to change notification settings - Fork 19
/
answer.py
54 lines (44 loc) · 1.56 KB
/
answer.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
#------------------------------------------------------------------------------
class Solution:
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
list = []
# Check columns
for i in range(9):
for j in range (9):
curr = board[i][j]
if curr != '.':
if curr not in list:
list.append(curr)
else:
return False
list.clear()
# Check rows
for j in range(9):
for i in range (9):
curr = board[i][j]
if curr != '.':
if curr not in list:
list.append(curr)
else:
return False
list.clear()
# Check 3x3 boxes
for r in range(0, 9, 3):
for d in range(0, 9, 3):
for i in range(r, r+3):
for j in range(d, d+3):
curr = board[i][j]
if curr != '.':
if curr not in list:
list.append(curr)
else:
return False
list.clear()
return True
#------------------------------------------------------------------------------
#Testing