[leetcode 36] valid sudoku
2015-09-27 19:52
387 查看
1 题目
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.
2 思路
开始就以为是完全填完,看最后能不能填出来。
结果题目意思是根据已有的数据,判断是否已经挂了。这也是看完别人的代码才知道的。。
3 代码:
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.
2 思路
开始就以为是完全填完,看最后能不能填出来。
结果题目意思是根据已有的数据,判断是否已经挂了。这也是看完别人的代码才知道的。。
3 代码:
// only need to examin the providing num is Valid int len = board.length; Boolean[][] row = new Boolean[len][len]; Boolean[][] column = new Boolean[len][len]; Boolean[][] sub = new Boolean[len][len]; for (int i = 0; i < sub.length; i++) { Arrays.fill(row[i], false); Arrays.fill(column[i], false); Arrays.fill(sub[i], false); } for(int i=0;i<len;i++){ for(int j=0;j<len;j++){ if(board[i][j] != '.'){ int num = board[i][j] - '1'; int k = i/3*3+j/3; if(row[i][num] || column[j][num] || sub[k][num]){ return false; } row[i][num]=column[j][num]=sub[k][num] = true; } } } return true; }
相关文章推荐
- Mark一下
- 链表的冒泡排序
- getchar()用法
- redis.conf配置详细解析
- Redis 作为多个Windows服务运行配置方法
- C语言保留字
- 这次来了就不走了。Java集合框架(总)
- 无线路由器连接WAN口上不了网的解决方案
- 1
- 如何编写符合web标准的XHTML文档
- Ubuntu 远程配置 openfire
- Leetcode---Remove Duplicates from Sorted List
- Mac下搭建php开发环境
- Floyed判环/龟兔算法
- 第二周(9.21-9.27)
- 关于坑爹的PopupWindow的“阻塞”争议问题:Android没有真正的“阻塞式”对话框
- Android Custom View --- Continuous Slider(连续滑动器)
- 名词解释
- [LeetCode][JavaScript]Pascal's Triangle II
- Android——DDMS简单介绍