leetcode---Valid Sudoku
来源:互联网 发布:mysql hint 用法 编辑:程序博客网 时间:2024/05/16 03:36
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 ‘.’.
class Solution {public: bool isValidSudoku(vector<vector<char>>& board) { int cnt[10]; for(int i=0; i<9; i++) //每一行 { memset(cnt, 0, sizeof(cnt)); for(int j=0; j<9; j++) { if(board[i][j] != '.') { cnt[board[i][j]-'0']++; if(cnt[board[i][j]-'0'] > 1) return false; } } } for(int i=0; i<9; i++) //每一列 { memset(cnt, 0, sizeof(cnt)); for(int j=0; j<9; j++) { if(board[j][i] != '.') { cnt[board[j][i]-'0']++; if(cnt[board[j][i]-'0'] > 1) return false; } } } for(int i=0; i<9; i+=3) //每个宫 { for(int j=0; j<9; j+=3) { memset(cnt, 0, sizeof(cnt)); for(int a=i; a<i+3; a++) { for(int b=j; b<j+3; b++) { if(board[a][b] != '.') { cnt[board[a][b]-'0']++; if(cnt[board[a][b]-'0'] > 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)
- spring事务传播行为种类
- 安装Kylin
- HDU——5667Sequence(矩阵快速幂+费马小定理应用)
- python(九)模块
- JS实现浏览器全屏和退出全屏
- leetcode---Valid Sudoku
- 349. Intersection of Two Arrays
- C指针操作——把ip字符串转换成ip range字符串
- 第1章 从容器到容器云
- AlertDialog自定义整个布局去掉原有的标题按钮等
- poj 3321
- Maven常用仓库地址以及手动添加jar包到仓库
- 实现跨域cookie共享(转载)
- 开启nginx目录文件列表显示功能