-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path36.有效的数独.py
More file actions
47 lines (42 loc) · 1.31 KB
/
36.有效的数独.py
File metadata and controls
47 lines (42 loc) · 1.31 KB
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
#
# @lc app=leetcode.cn id=36 lang=python3
#
# [36] 有效的数独
#
# @lc code=start
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
# 判断行
for i in range(9):
store = []
for j in range(9):
if board[i][j] == '.':
continue
if board[i][j] in store:
return False
else:
store.append(board[i][j])
# 判断列
for j in range(9):
store = []
for i in range(9):
if board[i][j] == '.':
continue
if board[i][j] in store:
return False
else:
store.append(board[i][j])
# 判断九宫格
for i in range(0, 9, 3):
for j in range(0, 9, 3):
store = []
for x in range(i, i+3):
for y in range(j, j+3):
if board[x][y] == '.':
continue
if board[x][y] in store:
return False
else:
store.append(board[x][y])
return True
# @lc code=end