LeetCode 题解(231) : Valid Sudoku
来源:互联网 发布:数据挖掘看什么书 编辑:程序博客网 时间:2024/05/01 06:50
题目:
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.
C++和Java版略显笨重,这里就不给出了。Python版如下
class Solution(object): def isValidSudoku(self, board): """ :type board: List[List[str]] :rtype: bool """ rows, cols, cells = [[] for i in range(9)], [[]for i in range(9)], [[] for i in range(9)] for i in range(len(board)): for j in range(len(board[0])): e = board[i][j] if e != '.': if e in rows[i] or e in cols[j] or e in cells[(i / 3) * 3 + j / 3]: return False else: rows[i].append(e) cols[j].append(e) cells[(i / 3 * 3 + j / 3)].append(e) return True
0 0
- LeetCode 题解(231) : Valid Sudoku
- LeetCode题解:Valid Sudoku
- LeetCode题解:Valid Sudoku
- leetcode 题解 || Valid Sudoku 问题
- leetcode题解-36.Valid Sudoku
- leetcode题解-36. Valid Sudoku
- LeetCode题解——Valid Sudoku
- 【E】【59】【leetcode题解】Valid Sudoku
- 【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
- jQuery ajax - serialize() 方法
- CYC-怎么制作手机号中间是*****
- FizzBuzz问题
- 2422 Pieczęć(pie)(模拟)
- HTML5 拖放实例
- LeetCode 题解(231) : Valid Sudoku
- 伪静态URLRewrite学习笔记
- python gflags
- 不能将值 NULL 插入列 'ID',表 列不允许有 Null 值.
- nginx + passenger 出现 Cannot stat .../config.ru': Permission denied 的错误的解决办法
- JS显示时间
- ThinkPHP——RBAC不同用户登录系统显示不同权限
- java web与discuz社区整合(二)
- 【读书笔记:C++ primer plus 第六版 中文版】第17章 输入、输出和文件