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-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.
分析:
每一行,每一列没有相同的数字,每一个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 其中,未填入 ...
随机推荐
- 【Python】01 - 常见用法随见随梳理
1. range() 和 xrange()的区别 for x in range(5): print x for x in xrange(5): print x 这么看,range和xrange返回的值 ...
- mysql事件关闭解决办法
Mysql 事件event_scheduler是OFF 开启 Event Scheduler,以下4种方式等效 SET GLOBAL event_scheduler = ON; SET @@globa ...
- 腾讯云的对象存储COS
什么是对象存储COS Clound Object Storage,COS,专门为企业和开发者们提供能够存储海量的分布式存储服务,用户可以随时通过互联网对大量数据进行批量存储和处理,在任意位置存储和检索 ...
- jquery 增加与删除数组元素
1.数组元素的添加 demoArray.push(value); var demo=new Array(); var key=[4,5]; demo.push(1);//插入数字 demo.push( ...
- svg路径动画心得
svg动画,随着路线运动,项目中需要用到,接触的时候感觉很高级,但是不会-无从下手呀!于是在网上找相关资料,先借鉴再修改成自己的. <svg width="500" heig ...
- Jquery实现表单动态加减、ajax表单提交
一直在搞Java后台开发,记得刚工作那一两年时间搞过前后端交互开发,用的东西也是五花八门,当时觉得做页面展示给别人看,是很有成就的事情,不过现在感觉自己跟纯前端开发比起来弱爆了,不过如果你的目标是作为 ...
- transition(过渡)
transition:过渡 渡过渡原理:原始状态a状态-向-最终结束状态b状态 格式:transition: all 1s linear; 过渡的四个参数: 1.参与过渡的属性(属性(width)/a ...
- IComparer 与 IComparable
static void Main() { var people = new ArrayList(); people.AddRange(new ArrayList { }, }, }, } }); Co ...
- cocos2d-x安装
mac 安装2.2.6为例 1.进入cocos2d-x/tools/project-creator/ 2.输入 python create_project.py -project HelloWorld ...
- ASP.NET底层与各个组件的初步认识与理解 (转载)
ASP.NET底层的初步认识与理解 最近在国外的网站乱走一通,发现一些比较好的文章,收集整理加于自己的理解,作为笔记形式记录下来,让以后自己有个回忆. ASP.NET是一个非常强大的构建Web应用 ...