-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalid-sudoku.py
37 lines (34 loc) · 1.01 KB
/
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
33
34
35
36
37
class Solution:
#given a list of lists of strings, 9*9
#return a bool
def isValidSudoku(self, board):
for i in range(9):
que = []
for j in range(9):
que.append(board[i][j])
if not self.cal(que):
return False
for j in range(9):
que = []
for i in range(9):
que.append(board[i][j])
if not self.cal(que):
return False
for x in range(3):
for y in range(3):
que = []
for i in range(3):
for j in range(3):
que.append(board[x*3+i][y*3+j])
if not self.cal(que):
return False
return True
def cal(self, que):
can = set()
for x in que:
if x == '.':
continue
if x in can:
return False
can.add(x)
return True