LeetCode:M-36. Valid Sudoku
来源:互联网 发布:vb.net 获取网页内容 编辑:程序博客网 时间:2024/06/05 02:07
Link
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.
数独规则 :
There are just 3 rules to Sudoku.
Each row must have the numbers 1-9 occuring just once.
Each column must have the numbers 1-9 occuring just once.
And the numbers 1-9 must occur just once in each of the 9 sub-boxes of the grid.
class Solution { public boolean isValidSudoku(char[][] board) { //注意数字是从1~9,所以数组长度9+1=10 boolean[][] rowUsed = new boolean[9][10];//标记行中用过的数字 boolean[][] columnUsed = new boolean[9][10];//标记列中用过的数字 boolean[][] squareUsed = new boolean[9][10];//标记3*3方格中用过的数字 for(int i=0; i<board.length; i++){ for(int j=0; j<board[0].length; j++){ if(board[i][j]!='.'){ int num = Integer.valueOf(board[i][j]+""); int k = i/3*3+j/3;//k表示第几个3*3方格 if(rowUsed[i][num] || columnUsed[j][num] || squareUsed[k][num]) return false; rowUsed[i][num] = columnUsed[j][num] = squareUsed[k][num] = true; } } } return true; }}
阅读全文
0 0
- LeetCode:M-36. Valid Sudoku
- [LeetCode]36.Valid Sudoku
- LeetCode --- 36. Valid Sudoku
- LeetCode 36.Valid Sudoku
- [Leetcode] 36. Valid Sudoku
- 【leetcode】36. Valid Sudoku
- [leetcode] 36. Valid Sudoku
- Leetcode 36. Valid Sudoku
- 36. Valid Sudoku LeetCode
- leetcode 36. Valid Sudoku
- LeetCode *** 36. Valid Sudoku
- leetcode 36. Valid Sudoku
- [LeetCode]36. Valid Sudoku
- LeetCode 36. Valid Sudoku
- leetcode-36. Valid Sudoku
- 36.[Leetcode]Valid Sudoku
- Leetcode 36.Valid Sudoku
- LeetCode-36.Valid Sudoku
- 数组的初始化方式
- 初识junit
- activiti学习--04流程定义:流程定义组成+部署流程定义+查询流程定义+删除流程定义+删除流程定义+查询最新版本的流程定+查询最新版本的流程定义
- 互联网新闻报道中的突发事件识别研究
- Tensorflow--逻辑回归
- LeetCode:M-36. Valid Sudoku
- nvm、nrm、npm 安装和使用详解
- C++构造函数成员初始值问题
- 批处理
- 测试工具--给自己备份学习
- VIN码车架号进行识别OCR录入
- Cordova开发之IOS插件开发
- 关于oracle查找重复数据
- 生活中的某一天