【leetcode】36. Valid Sudoku(判断能否是合法的数独puzzle)
Share Determine if a 9 x 9 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 nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be valid but is not necessarily solvable. Only the filled cells need to be validated according to the mentioned rules.
分别建立三个hash_set 注意这是建立个hash_set数组 【】,而不是单单建立一个hash表。
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
int n=9;// 题目中给的是9x9 的sudoku puzzle
unordered_set<char> row[n]; //这是创建hash数组 之前没这么用过
unordered_set<char> cloumn[n];
unordered_set<char> square[n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
int sr=i/3;
int sc=j/3;
int sq=sr*3+sc;
char tmp=board[i][j];
if(tmp=='.') continue;
if(row[i].count(tmp)>0 || cloumn[j].count(tmp)>0 || square[sq].count(tmp)>0)
{
return false;
}
row[i].insert(tmp);
cloumn[j].insert(tmp);
square[sq].insert(tmp); }
}
return true; }
};
【leetcode】36. Valid Sudoku(判断能否是合法的数独puzzle)的更多相关文章
- 36. Valid Sudoku 判断九九有效的数独
[抄题]: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according ...
- LeetCode:36. Valid Sudoku,数独是否有效
LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...
- [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
Problem: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board ...
- Java [leetcode 36]Valid Sudoku
题目描述: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board cou ...
- 蜗牛慢慢爬 LeetCode 36.Valid Sudoku [Difficulty: Medium]
题目 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...
- 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(合法的数独)
题目链接: https://leetcode.com/problems/valid-sudoku/?tab=Description 给出一个二维数组,数组大小为数独的大小,即9*9 其中,未填入 ...
- [leetcode]36. Valid Sudoku验证数独
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...
随机推荐
- shell 脚本控制命令的执行顺序
&&,||,(),{},& 五个符号的运用shell脚本执行命令的时候,有时候会依赖于前一个命令是否执行成功.而&&和||就是用来判断前一个命令执行效果的. 也 ...
- linux 的 逻辑卷管理
lvm 逻辑卷管理器 关于逻辑卷管理lvm的一些操作 新建磁盘 sdcfdisk /dev/sdc 创建分区,更改分区id 为8e,改变分区类型为 lvm linux 创建物理卷与pv相关 pvcre ...
- Java安全之Thymeleaf SSTI分析
Java安全之Thymeleaf SSTI分析 写在前面 文章首发:https://www.anquanke.com/post/id/254519 最近看了一遍Thymeleaf,借此机会学习一下Th ...
- 合并代码操作 | git fetch 与 git pull
前言 首先我们要说简单说git的运行机制.git分为本地仓库和远程仓库,我们一般情况都是写完代码,commit到本地仓库(生成本地仓的commit ID,代表当前提交代码的版本号),然后push到远程 ...
- fabric运行错误汇总
Error generating signCA for org org1.example.com: Failed storing key [ECDSAP256]: Failed storing ECD ...
- easypoi导出动态表头excel
easypoi导出动态表头excel 1: springBoot项目maven依赖: <dependency> <groupId>cn.afterturn</groupI ...
- 蓝图before request
方法1 @bp.before_request def test(): print("test") 方法2 def bp_before_request(): print(test) ...
- python-变量&底层存储原理
目录 1.变量 1.变量如何使用 2.变量存储的原理 --[ 重点 ] 3.变量存储要遵循印射关系 4.变量三要素 2.常量 3.底层优化 4.垃圾回收机制 1.变量 1.变量如何使用 1.什么是变量 ...
- 1组-Alpha冲刺-3/6
一.基本情况 队名:震震带着六菜鸟 组长博客:https://www.cnblogs.com/Klein-Wang/p/15544334.html 小组人数:7人 二.冲刺概况汇报 王业震 过去两天完 ...
- liunx基础知识点1:系统管理相关命令、目录操作命令、文本编辑、关闭防火墙、重启和关闭
Linux(一) liunx系统那么重要,作为一个测试人员,不掌握你就损失了好几千,为了这个钱,也为了面子,什么鬼?我爱膨胀.你看看这些知识喽.我整理的,可费工夫了. 下次给大家一个面试题啊,更直观