[抄题]:

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

  1. Each row must contain the digits 1-9 without repetition.
  2. Each column must contain the digits 1-9 without repetition.
  3. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-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的代码] :

[潜台词] :

  1. class Solution {
  2. public boolean isValidSudoku(char[][] board) {
  3.  
  4. //for loop, judge row, col, and box
  5. for (int i = 0; i < 9; i++) {
  6. //initialization: 3 sets in each new row
  7. HashSet<Character> row = new HashSet<>();
  8. HashSet<Character> col = new HashSet<>();
  9. HashSet<Character> box = new HashSet<>();
  10.  
  11. for (int j = 0; j < 9; j++) {
  12. //judge row, col
  13. if (board[i][j] != '.' && !row.add(board[i][j])) return false;
  14. if (board[j][i] != '.' && !col.add(board[j][i])) return false;
  15. //judge box
  16. //same for each row
  17. int rowIndex = 3 * (i / 3);
  18. System.out.println("rowIndex = " + rowIndex);
  19. int colIndex = 3 * (i % 3);
  20. System.out.println("colIndex = " + colIndex);
  21. System.out.println("-------------");
  22. //different for each col
  23. if (board[rowIndex + j / 3][colIndex + j % 3] != '.' && !box.add(board[rowIndex + j / 3][colIndex + j % 3])) return false;
  24. }
  25. }
  26.  
  27. return true;
  28. }
  29. }

36. Valid Sudoku 判断九九有效的数独的更多相关文章

  1. LeetCode:36. Valid Sudoku,数独是否有效

    LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...

  2. leetcode 37. Sudoku Solver 36. Valid Sudoku 数独问题

    三星机试也考了类似的题目,只不过是要针对给出的数独修改其中三个错误数字,总过10个测试用例只过了3个与世界500强无缘了 36. Valid Sudoku Determine if a Sudoku ...

  3. 【LeetCode】36. Valid Sudoku 解题报告(Python)

    [LeetCode]36. Valid Sudoku 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址 ...

  4. [Leetcode][Python]36: Valid Sudoku

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 36: Valid Sudokuhttps://oj.leetcode.com ...

  5. [LeetCode] 36. Valid Sudoku 验证数独

    Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...

  6. leetCode 36.Valid Sudoku(有效的数独) 解题思路和方法

    Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku bo ...

  7. LeetCode 36 Valid Sudoku

    Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...

  8. 蜗牛慢慢爬 LeetCode 36.Valid Sudoku [Difficulty: Medium]

    题目 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  9. 36. Valid Sudoku

    ============= Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku b ...

随机推荐

  1. design_patterns_in_typescript 学习

    https://github.com/torokmark/design_patterns_in_typescript Creational Singleton [A class of which on ...

  2. C#程序终止问题CLR20R3解决方法

    去年在公司局域网部署了一个C#编写的自动更新的工具软件,最近有同事反映部分Win7系统电脑安装不了,程序自动安装不了,免安装版又运行不了. 没办法,先解决自动安装不了的问题,最后通过关闭防火墙得以解决 ...

  3. Markdown语法说明(转)

    Markdown语法说明(转) Markdown创始人John Gruber的语法说明 附上本文链接 NOTE: This is Simplelified Chinese Edition Docume ...

  4. 【idea】之使用SVN一些技巧

    @Copy https://www.cnblogs.com/whc321/p/5669804.html

  5. kafuka资料学习

    http://blog.csdn.net/hmsiwtv/article/details/46960053

  6. c# 数据结构 ArrayList

    数据结构 描述数据之间的关系 行为:添加数据,删除数据,插入数据,查找数据,修改数据 追加数据:向这个结构的末尾添加一个数据 删除数据:在这个结构中删除你指定的数据 插入数据:向这个结构中某一个位置插 ...

  7. Emscripten 安装和使用

    OS: Windows 10 x64 I. install 0. pre install Python2.7 Node js Java 1. down git clone https://github ...

  8. rabbitmq (一)用法

    首先,主机一是window系统,虚拟机二 ubuntu, ubuntu部署了rabbitmq服务端.默认监听5672端口. 由于rabbitmq内部有严格的权限系统,使用之前必须配置好权限. 默认网页 ...

  9. 自动配置pom文件,构建maven项目jar包依赖关系,找到jar包运用到jmeter

    首先说下pom文件特别方便的优点: 什么是pom文件? POM(Project Object Model) 是Maven的基础. 它是一个XML文件,包含了Maven用来build项目所需要的项目配置 ...

  10. windows:plsql配置oracle连接

    1.plsql安装 此处省略,后续添加 2.plsql连接oracle: (1) 下载Instant client:http://www.oracle.com/technetwork/cn/topic ...