36. Valid Sudoku 判断九九有效的数独
[抄题]:
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:
- Each row must contain the digits
1-9
without repetition. - Each column must contain the digits
1-9
without repetition. - Each of the 9
3x3
sub-boxes of the grid must contain the digits1-9
without repetition.
A partially filled sudoku which is valid.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
不知道怎么判断每个单独的3*3: 三倍行数遍历+一倍列数遍历进入具体的3*3
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[一句话思路]:
每一行都新建三个集合,然后行重复为[i][j] 列重复为[j][i]
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
三倍行数遍历+一倍列数遍历进入具体的3*3
[复杂度]:Time complexity: O(mn) Space complexity: O(mn)
[算法思想:迭代/递归/分治/贪心]:
[关键模板化代码]:
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
[是否头一次写此类driver funcion的代码] :
[潜台词] :
- class Solution {
- public boolean isValidSudoku(char[][] board) {
- //for loop, judge row, col, and box
- for (int i = 0; i < 9; i++) {
- //initialization: 3 sets in each new row
- HashSet<Character> row = new HashSet<>();
- HashSet<Character> col = new HashSet<>();
- HashSet<Character> box = new HashSet<>();
- for (int j = 0; j < 9; j++) {
- //judge row, col
- if (board[i][j] != '.' && !row.add(board[i][j])) return false;
- if (board[j][i] != '.' && !col.add(board[j][i])) return false;
- //judge box
- //same for each row
- int rowIndex = 3 * (i / 3);
- System.out.println("rowIndex = " + rowIndex);
- int colIndex = 3 * (i % 3);
- System.out.println("colIndex = " + colIndex);
- System.out.println("-------------");
- //different for each col
- if (board[rowIndex + j / 3][colIndex + j % 3] != '.' && !box.add(board[rowIndex + j / 3][colIndex + j % 3])) return false;
- }
- }
- return true;
- }
- }
36. Valid Sudoku 判断九九有效的数独的更多相关文章
- LeetCode:36. Valid Sudoku,数独是否有效
LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...
- leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题
三星机试也考了类似的题目,只不过是要针对给出的数独修改其中三个错误数字,总过10个测试用例只过了3个与世界500强无缘了 36. Valid Sudoku Determine if a Sudoku ...
- 【LeetCode】36. Valid Sudoku 解题报告(Python)
[LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...
- [Leetcode][Python]36: Valid Sudoku
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 36: Valid Sudokuhttps://oj.leetcode.com ...
- [LeetCode] 36. Valid Sudoku 验证数独
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...
- leetCode 36.Valid Sudoku(有效的数独) 解题思路和方法
Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku bo ...
- LeetCode 36 Valid Sudoku
Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...
- 蜗牛慢慢爬 LeetCode 36.Valid Sudoku [Difficulty: Medium]
题目 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...
- 36. Valid Sudoku
============= Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku b ...
随机推荐
- design_patterns_in_typescript 学习
https://github.com/torokmark/design_patterns_in_typescript Creational Singleton [A class of which on ...
- C#程序终止问题CLR20R3解决方法
去年在公司局域网部署了一个C#编写的自动更新的工具软件,最近有同事反映部分Win7系统电脑安装不了,程序自动安装不了,免安装版又运行不了. 没办法,先解决自动安装不了的问题,最后通过关闭防火墙得以解决 ...
- Markdown语法说明(转)
Markdown语法说明(转) Markdown创始人John Gruber的语法说明 附上本文链接 NOTE: This is Simplelified Chinese Edition Docume ...
- 【idea】之使用SVN一些技巧
@Copy https://www.cnblogs.com/whc321/p/5669804.html
- kafuka资料学习
http://blog.csdn.net/hmsiwtv/article/details/46960053
- c# 数据结构 ArrayList
数据结构 描述数据之间的关系 行为:添加数据,删除数据,插入数据,查找数据,修改数据 追加数据:向这个结构的末尾添加一个数据 删除数据:在这个结构中删除你指定的数据 插入数据:向这个结构中某一个位置插 ...
- Emscripten 安装和使用
OS: Windows 10 x64 I. install 0. pre install Python2.7 Node js Java 1. down git clone https://github ...
- rabbitmq (一)用法
首先,主机一是window系统,虚拟机二 ubuntu, ubuntu部署了rabbitmq服务端.默认监听5672端口. 由于rabbitmq内部有严格的权限系统,使用之前必须配置好权限. 默认网页 ...
- 自动配置pom文件,构建maven项目jar包依赖关系,找到jar包运用到jmeter
首先说下pom文件特别方便的优点: 什么是pom文件? POM(Project Object Model) 是Maven的基础. 它是一个XML文件,包含了Maven用来build项目所需要的项目配置 ...
- windows:plsql配置oracle连接
1.plsql安装 此处省略,后续添加 2.plsql连接oracle: (1) 下载Instant client:http://www.oracle.com/technetwork/cn/topic ...