LeetCode 36. Valid Sudoku
2016-07-24 15:16
281 查看
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.
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.
class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { map<char, int> m; int i, j; for(i = 0; i < 9; i ++){ m.clear(); for(j = 0; j < 9; j ++){ if(board[i][j] != '.'){ if(m[board[i][j]] == 1) return false; m[board[i][j]] = 1; } } } for(i = 0; i < 9; i ++){ m.clear(); for(j = 0; j < 9; j ++){ if(board[j][i] != '.'){ if(m[board[j][i]] == 1) return false; m[board[j][i]] = 1; } } } for(i = 0; i < 7; i += 3){ for(j = 0; j < 7; j += 3){ int k, t; m.clear(); for(k = i; k < 3 + i; k ++){ for(t = j; t < 3 + j; t ++){ if(board[k][t] != '.'){ if(m[board[k][t]] == 1) return false; m[board[k][t]] = 1; } } } } } return true; } };
相关文章推荐
- C语言总复习第一阶段部分练习题及其代码
- 常用排序算法之堆排序
- 时间换算(java)
- 使用Axis发布Web Service
- 常用排序算法之选择排序
- 多线程及线程并发库
- PAT(B) - 1004. 成绩排名 (20)
- CodeForces 427C Checkposts (强连通分量Tarjan模板题)
- UML之部署图and构件图
- JAVA面向对象-----成员内部类的访问方式
- JAVA面向对象-----成员内部类的访问方式
- 常用排序算法之归并排序
- 个位数,十位数,百位数等程序常用英文变量名该怎么写?
- 常用排序算法之希尔排序
- 编译ITK
- DataTables 自定义
- java 命令notes
- CentOS7 升级python同时解决yum损坏问题
- 简单dp算法——Sumsets
- poj 2524 Ubiquitous Religions [并查集]