72-Valid Sudoku
2016-05-17 15:31
253 查看
Valid Sudoku My Submissions QuestionEditorial Solution
Total Accepted: 74295 Total Submissions: 241017 Difficulty: Easy
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.
数独游戏的介绍,http://sudoku.com.au/TheRules.aspx
本题不用填充表格,只要判定是否合法就行
所以只要满足三个规则即可:
1.行包含1到9中几个,且不重复
2.列包含1到9中几个,且不重复
3.9宫格每格包含1到9几个,且不重复
Total Accepted: 74295 Total Submissions: 241017 Difficulty: Easy
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.
数独游戏的介绍,http://sudoku.com.au/TheRules.aspx
本题不用填充表格,只要判定是否合法就行
所以只要满足三个规则即可:
1.行包含1到9中几个,且不重复
2.列包含1到9中几个,且不重复
3.9宫格每格包含1到9几个,且不重复
class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { bool used[9]; for(int i =0;i<9;++i){ fill(used,used+9,false); for(int j=0;j<9;++j) //判定行 if(!check(board[i][j],used)) return false; fill(used,used+9,false); for(int j=0;j<9;++j) //判定列 if(!check(board[j][i],used)) return false; } for(int r =0;r<3;++r) //9个模块 for(int c=0;c<3;++c){ fill(used,used+9,false); for(int i=3*r;i<3*r+3;++i) //每个9宫格 for(int j=3*c;j<3*c+3;++j) if(!check(board[i][j],used)) return false; } return true; } bool check(char c,bool used[9]) { if(c=='.')return true; if(used[c-'1']) return false; return used[c-'1']=true; } };
相关文章推荐
- Android Zygote
- Linux简介
- 从Git仓库中恢复已删除的分支、文件或丢失的commit
- git 基本命令
- shell脚本循环删除旧tag
- linux下lrzsz安装过程,SecureCRT上传下载文件工具
- Git 常用命令合集
- java 地址记录
- Oracle 树操作(select…start with…connect by…prior)
- Uiautomator在Android Studio下的环境搭建
- MongoDB的安装
- jQuery Mobile操作HTML5的常用函数总结
- c和c++接口互调
- 利用maven将项目依赖的jar提取到指定文件夹
- OpenCV -- win7下配置OpenCV的Qt开发环境
- java中queue的使用
- (转)亚马逊开放机器学习系统DSSTNE源代码:挑战谷歌TensorFlow
- 【经典算法】——KMP,深入讲解next数组的求解
- 从oracle 11g导出->12c 导入 ,遇到ORA-39213: Metadata processing is not available
- μCOS-Ⅲ——常用注意事项