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-9without repetition. - Each column must contain the digits
1-9without repetition. - Each of the 9
3x3sub-boxes of the grid must contain the digits1-9without 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 ...
随机推荐
- PythonStudy——阶段总结
每个数据类型的最大特点是什么? (1)int整型:用于存放整形对象,是不可变类型.若将一个整数赋值给一个变量名,python可自动将其设置为int型. 例如:age = 30 这里的age对象的typ ...
- laravel的filter()方法的使用 (方法使用给定的回调函数过滤集合的内容,只留下那些通过给定真实测试的内容)
filter 方法使用给定的回调函数过滤集合的内容,只留下那些通过给定真实测试的内容: $collection = collect([1, 2, 3, 4]); $filtered = $collec ...
- bootstrapValidator关于js,jquery动态赋值不触发验证(不能捕获“程序赋值事件”)解决办法
//触发oninput事件 //propertychange 兼容ie678 $('#captainName').on('input propertychange', function() { }); ...
- Linux platform平台总线、平台设备、平台驱动
平台总线(platform_bus)的需求来源? 随着soc的升级,S3C2440->S3C6410->S5PV210->4412,以前的程序就得重新写一遍,做着大量的重复工作, 人 ...
- 淘宝客知道这几个ID,收入将会提高50%
基础问题天天说,天天有人问.这篇文章写点基础的.特别对新手的帮助会很大哦. 1,PID,做淘宝客不知道PID,赚到钱也会被冻结. 如何手动获取PID 2,单品ID,淘宝商品的唯一识别编号,和身份证一样 ...
- RE validator
package com.office.utility; import java.util.regex.Pattern; /** * 校验器:利用正则表达式校验邮箱.手机号等 * * @a ...
- C# 调用Tesseract实现OCR
介绍 Tesseract是一个基于Apache2.0协议开源的跨平台ocr引擎,支持多种语言的识别,在Windows和Linux上都有良好的支持. 创建工程 创建一个C#的控制台工程 添加System ...
- day31网络编程
网络编程1. 目标:编写一个C/S架构的软件 C/S: Client(用户端)--------基于网络----------Server(服务端) B/S: Browser-------基于 ...
- Tomcat、TongWeb5.0、TongWeb6.0部署solr
将solr,solr-4.7.2复制到某一路径下,比如F盘根目录. 1.tomcat中进行配置,配置如下: <Context docBase="F:/solr" reload ...
- [持续交付实践] pipeline使用:Multibranch Pipeline
前言 在探讨multiBranch Pipeline之前,很有必要先探讨下如何制定有效的代码分支管理规范,使用高效的版本控制系统,并对构建产物及其依赖进行管理.我们首先要强调,需要进行版本控制的不仅是 ...