[Leetcode]_36 Valid Sudoku
来源:互联网 发布:淘宝上的qq号能买吗 编辑:程序博客网 时间:2024/06/05 07:20
/** * Index: 36 * Title: Valid Sudoku * Author: ltree98 **/
检查数独是否合法。
数独合法的条件:
1、所处行内没有重复数字
2、所处列内没有重复数字
3、所处方形格内没有重复数字
检查行、列直接查找就可以了,检查方格就要换算一下了。
row/3 * 3 + col/3
接下来暴力查一下就行了。
class Solution {public: bool isValidSudoku(vector<vector<char>>& board) { int checkRow[10][10] = {0}, checkCol[10][10] = {0}, checkSquare[10][10] = {0}; for(int i = 0; i < board.size(); i++) { for(int j = 0; j < board[i].size(); j++) { if(board[i][j] != '.') { int num = board[i][j] - '0'; int s = i/3*3 + j/3; if(checkRow[i][num] || checkCol[j][num] || checkSquare[s][num]) return false; checkRow[i][num] = checkCol[j][num] = checkSquare[s][num] = 1; } } } return true; }};
阅读全文
0 0
- [Leetcode]_36 Valid Sudoku
- 【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
- linux上activiti工作流成图中文乱码
- DHCP笔记
- day09 集合 list Arraryist LinkedList Vector HashSet treeSet comparable Iterator 如有错多多指教
- 杭电oj1021 四个一周期 递归超限
- Fibonacci Again!
- [Leetcode]_36 Valid Sudoku
- hdu 多校联赛 Is Derek lying?
- 主席树(Kth number,HDU 2665)
- hdfs查看目录大小文件大小
- 【ARM】控制寄存器的几种方式
- EasyHook 中部分函数的实现分析—-申请钩子
- spring4.0之后,自定义属性编辑器的配置变化
- 获取历史和实时股票数据接口
- redis过期时间的过期策略