Leetcode: Valid Sudoku
来源:互联网 发布:淘宝日用品优质店铺 编辑:程序博客网 时间:2024/06/07 23:59
Question
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.
A partially filled sudoku which is valid.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
Hide Tags Hash Table
Analysis
check every row, col and
Solution
class Solution: # @param {character[][]} board # @return {boolean} def isValidSudoku(self, board): n = len(board) for row in range(n/3): for col in range(n/3): array = [] temp = board[row*3:row*3+3] for i in range(3): array += temp[i][col*3:col*3+3] if not self.helper(array): return False for row in range(n): if not self.helper(board[row]): return False for col in range(n): array = [] for row in range(n): array += [ board[row][col] ] if not self.helper(array): return False return True def helper(self, array): dict = {} for val in array: if val!='.': if val in dict: return False else: dict[val] = val return True
0 0
- 【LeetCode】Valid Sudoku && Sudoku Solver
- [Leetcode]Sudoku Solver&&Valid Sudoku
- leetcode Valid Sudoku & Sudoku Solver
- LeetCode : Valid Sudoku
- [LeetCode]Valid Sudoku
- [leetcode] Valid Sudoku
- LeetCode-Valid Sudoku
- LeetCode Valid Sudoku
- LeetCode - Valid Sudoku
- LeetCode:Valid Sudoku
- leetcode-036:Valid Sudoku
- Leetcode: Valid Sudoku
- LeetCode题解:Valid Sudoku
- 【LeetCode】 Valid Sudoku
- Leetcode Valid Sudoku
- LeetCode | Valid Sudoku
- LeetCode Valid Sudoku
- [Leetcode] Valid Sudoku (Java)
- 提高第24课时,实践2,成绩处理V2.0 数组指针版
- 6种常见的数据加载模式设计
- ArcGIS教程:使用概念模型创建地图(一)
- C++内存管理
- [Leetcode 40, Medium] Combination Sum II
- Leetcode: Valid Sudoku
- 从Linux内核中获取真随机数
- 代码段、数据段、BSS段、堆和栈之间的区别
- Android反编译xml文件
- SpringMVC文件上传 多文件上传实例
- Cadence PCB Editor pcb 布局时,元件的对齐
- ArcGIS教程:使用概念模型创建地图(二)
- 谷歌推荐的技术能力提升指南
- C++常用库