文章目录
- 1. 题目
- 2. 解答
数据结构算法操作试题(C++/Python):数据结构算法操作试题(C++/Python)——目录
1. 题目
leetcode 链接:https://leetcode-cn.com/problems/valid-sudoku/submissions/
2. 解答
python: 272ms, 11.9mb
复制代码
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
28class Solution(object): def isValidSudoku(self, board): """ :type board: List[List[str]] :rtype: bool """ for i in range(9): if not self.isvalidList(board[i]) : return False if not self.isvalidList([j[i] for j in board]) : return False indexList = [0, 3, 6] if i % 3 == 0: for j in indexList: numsList = [] numsList += board[i][j:j + 3] numsList += board[i + 1][j:j + 3] numsList += board[i + 2][j:j + 3] print numsList if not self.isvalidList(numsList) : return False return True def isvalidList(self, myList): tmpList = [] for i in myList: if i != "." and i in tmpList: return False else: tmpList.append(i) return True
其他方法看 leetcode 链接 评论区~
最后
以上就是慈祥乐曲最近收集整理的关于数据结构算法操作试题(C++/Python)——有效的数独的全部内容,更多相关数据结构算法操作试题(C++/Python)——有效内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复