LeetCode 36. Valid Sudoku (C++)
题目:
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.
![]()
分析:
每一行,每一列没有相同的数字,每一个3*3的小正方形中也没有相同的数字。可以使用数组,map,set等等来判断。
程序:
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
map<char,int> m;
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
if (board[i][j] != '.'){
if (m[board[i][j]]) return false;
m[board[i][j]]++;
}
}
m.clear();
}
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
if (board[j][i] != '.'){
if (m[board[j][i]]) return false;
m[board[j][i]]++;
}
}
m.clear();
}
for (int i = ; i < ; i++){
for (int j = ; j < ; j++){
for (int r = i*; r < i*+; r++){
for (int l = j*; l < j*+; l++){
if (board[r][l] != '.'){
if (m[board[r][l]]) return false;
m[board[r][l]]++;
}
}
}
m.clear();
}
}
return true;
}
};
LeetCode 36. Valid Sudoku (C++)的更多相关文章
- LeetCode:36. Valid Sudoku,数独是否有效
LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...
- 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 验证数独
Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to th ...
- [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 (Medium)
题目 Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according ...
- LeetCode 36 Valid Sudoku(合法的数独)
题目链接: https://leetcode.com/problems/valid-sudoku/?tab=Description 给出一个二维数组,数组大小为数独的大小,即9*9 其中,未填入 ...
随机推荐
- ABAP术语-World Wide Web
World Wide Web 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/21/1115728.html Internet service ...
- MySQL学习【第七篇索引管理及执行计划】
一.索引介绍 1.什么是索引? 索引由如字典,目的就是为了更快寻找到要找的内容. 令搜索查询的数据更有目的性,从而提高数据检索的能力 2.索引类型介绍 1.BTREE: B+树索引 2.HASH: H ...
- Ubuntu18.04安装mysql及相关配置
step 1: sudo apt-get update step 2: sudo apt-get install mysql-server step3: 查看mysql服务端是否开启 systemct ...
- pt-archiver数据归档
可以使用percona-toolkit包中的pt-archiver工具来进行历史数据归档 pt-archiver使用的场景: 1.清理线上过期数据. 2.清理过期数据,并把数据归档到本地归档表中,或者 ...
- querySelectorAll 和 getElementBy 方法的区别
作者:简生 链接:https://www.zhihu.com/question/24702250/answer/28695133 来源:知乎 1. W3C 标准 querySelectorAll 属于 ...
- MongoDB的高级使用
MongoDB的高级使用 1. Mongdb的索引备份以及和python交互 t255为mongodb中的集合 1.1 创建索引 索引的特点:提高查找的效率 不创建索引的情况下的查询: for(i=0 ...
- Redis全方位详解--磁盘持久化和容灾备份
序言 在上一篇博客中,博客介绍了redis的数据类型使用场景和redis分布式锁的正确姿势.我们知道一旦Redis重启,存在redis里面的数据就会全部丢失.所以这篇博客中向大家介绍Redis的磁盘持 ...
- Python - 入门基础(一)
1.解释器路径 #!/usr/bin/env python 2.编码 # -*- coding:utf8 -*- 1.ascill ---00000000 (8个位表示) 缺点:表示不了英文 2.u ...
- 【Spark】编程实战之模拟SparkRPC原理实现自定义RPC
1. 什么是RPC RPC(Remote Procedure Call)远程过程调用.在Hadoop和Spark中都使用了PRC,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的 ...
- POI导出excel文件样式
需求: 公司业务和银行挂钩,各种形式的数据之间交互性比较强,这就涉及到了存储形式之间的转换 比如数据库数据与excel文件之间的转换 解决: 我目前使用过的是POI转换数据库和文件之间的数据,下边上代 ...