Valid Sudoku
2015-08-25 23:27
288 查看
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.
Solution:
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.
Solution:
class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { vector<vector<bool> > row(9, vector<bool>(10, true)); vector<vector<bool> > col(9, vector<bool>(10, true)); vector<vector<bool> > small(9, vector<bool>(10, true)); for(int i = 0; i < 9; ++i) for(int j = 0; j < 9; ++j) { if(board[i][j] == '.') continue; int val = board[i][j] - '0'; if(row[i][val]) row[i][val] = false; else return false; if(col[j][val]) col[j][val] = false; else return false; if(small[(i/3)*3+j/3][val]) small[(i/3)*3+j/3][val] = false; else return false; } return true; } };
相关文章推荐
- 一段datepickerdialog与自定义Timepickerdialog限定时间范围的逻辑
- I/O多路复用模式与线程并发模式
- 单链表的反转(数据结构 面试题)
- Android硬件抽象层(HAL)模块编写规范
- 矩阵 ACdream1213 Matrix Multiplication
- hdoj 2647 Reward
- iOS UI基础-5.0 QQ框架(Storyboard)
- 第一个android和php的案例开始
- 关于虚函数
- Linux系统内部的名称解析与安全认证
- 内存模型(1)
- 程序员的年龄天花板
- 小练习--低仿系统计算器
- Map集合重要练习
- Spring MVC中的DispatcherServlet作用
- hibernate 总结一
- HDU 4407 Sum (莫比乌斯反演)
- 【java关键字-Thread】Thread.Join()的用法,及其实现线程顺序执行的原理
- Linux下Sed的用法详情
- C# WebService动态调用