Leetcode: Valid Sudoku
来源:互联网 发布:java 开源工作流 编辑:程序博客网 时间:2024/05/08 09:24
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.
判断数独是否合法,一个个的扫描,行、列、格子即可。
class Solution {public: bool isValidSudoku(vector<vector<char> > &board) { int size = board.size(); pair<int, int> points[] = {{0, 0,}, {0, 3}, {0, 6}, {3, 0}, {3, 3}, {3, 6}, {6, 0}, {6, 3}, {6, 6}}; for (int i = 0; i < size; ++i) { vector<int> row_count(size, 0); vector<int> col_count(size, 0); vector<int> box_count(size, 0); for (int j = 0; j < size; ++j) { if (board[i][j] != '.') { if (++row_count[board[i][j] - '1'] > 1) { return false; } } if (board[j][i] != '.') { if (++col_count[board[j][i] - '1'] > 1) { return false; } } int px = points[i].first + j / 3; int py = points[i].second + j % 3; if (board[px][py] != '.') { if (++box_count[board[px][py] - '1'] > 1) { return false; } } } } 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)
- libev源代码分析--事件模型 ae
- Ubuntu GCC不能编译sqrt()函数问题
- strcpy/strncpy/strcpy_s比较
- iOS 应用内支付(IAP)
- blockingQueue毒丸对象使用
- Leetcode: Valid Sudoku
- libev源代码分析--总体框架
- 黑马程序员-->07_面向对象
- 在xp或win7下 oracle11g通过exp/imp方式来对db数据的备份与还原
- C#构造函数
- 深入理解容器系列片之二--------ArrayList的总结
- 初次实验mysql游标
- 利用中位数进行快速排序
- MD5 加密