Problem:
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
.
A partially filled sudoku which is valid.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
Summary:
判断当前给出的数独是否满足条件。
Solution:
横向,纵向,每个3*3小方格分别判断。
class Solution {
public:
bool isValidSudoku(vector<vector<char>> board) {
int validRow[] = { }, validCol[] = { };
int validSqr[] = { }; for (int i = ; i < ; i++) {
memset(validRow, , sizeof(validRow));
memset(validCol, , sizeof(validCol)); for (int j = ; j < ; j++) {
if (board[i][j] != '.') {
char tmp = board[i][j];
if (!validRow[tmp - '' - ]) {
validRow[tmp - '' - ]++;
}
else {
return false;
}
} if (board[j][i] != '.') {
char tmp = board[j][i];
if (!validCol[tmp - '' - ]) {
validCol[tmp - '' - ]++;
}
else {
return false;
}
}
}
} for (int m = ; m < ; m++) {
for (int n = ; n < ; n++) {
memset(validSqr, , sizeof(validSqr)); for (int i = m * ; i < m * + ; i++) {
for (int j = n * ; j < n * + ; j++) {
if (board[i][j] != '.') {
char tmp = board[i][j];
if (!validSqr[tmp - '' - ]) {
validSqr[tmp - '' - ]++;
}
else {
return false;
}
} }
}
}
} return true;
} };
LeetCode 36 Valid Sudoku的更多相关文章
-
LeetCode:36. Valid Sudoku,数独是否有效
LeetCode:36. Valid Sudoku,数独是否有效 : 题目: LeetCode:36. Valid Sudoku 描述: Determine if a Sudoku is valid, ...
-
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 (C++)
题目: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according t ...
-
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 其中,未填入 ...
随机推荐
-
小议map排序问题
map有序无序?如果说有序, 这个顺序是怎么定义的? 安装put的先后顺序吗? 还是被put元素的内容呢? 经观察,应该是后者,跟put先后顺序无关, 跟内部实现有关(可能是hash排序的, 非大小排 ...
-
Android View之用户界面...
PS:Android的控件真的是很多...现在还在忙到控件...也是神了.... 学习内容: 1.Spinner下拉菜单... 2.AutoComplete TextView自动完成文本框... 1. ...
-
Struts2+Jquery实现ajax并返回json类型数据
来源于:http://my.oschina.net/simpleton/blog/139212 摘要 主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的 ...
-
Golang哲学思想
Golang是一门新语言,经过几年发展,慢慢地也已经被许多大公司认可.最大的特点是速度快,并发性好,与网络的功能结合好,是一门服务端语言,号称“网络时代的新语言”:另外还是一个编译型的Python.不 ...
-
gitlab备份与恢复操作方法
github私有仓库是收费的,有些代码不方便托管到外面的git仓库,因此就产生了自己搭建git服务器的需求. 好在有广大的开源人士的贡献,有了gitlab这一神器. 手动配置较多,直接用集成包: bi ...
-
适配器控件-Adapter
适配器对象派生自Android.widget.Adapter,它的作用包括:构造列表项控件,并将数据项绑定到列表项控件中. 常见的适配器有:数组适配器 ArrayAdapter,数据库适配器 Curs ...
-
秀才每天一篇之—SEO是什么?
[导读]SEO是什么?秀才搁笔七天以来.遇到非常多事情.站点被K ,排名掉了. 却找不出原因,開始迷茫了.以至于没有心情来照应这个博客,不好意思了,各位.在这七天以来.秀才一直在思考,SEO究竟应该怎 ...
-
Windows 安装*db
1. 下载 下载地址: http://www.mongodb.org/downloads 我这里用的是:mongodb-win32-x86_64-2008plus-2.4.5.zip 2. 设置目录 ...
-
STM32F4xx FPU的设置
原文:http://blog.csdn.net/dlutxie/article/details/7980389 浮点运算一直是定点CPU的难题,比如一个简单的1.1+1.1,定点CPU必须要按照IEE ...
-
AJAX初识(原生JS版AJAX和Jquery版AJAX)
一.什么是JSON 1.介绍 JSON独立于语言,是一种与语言无关的数据格式. JSON指的是JavaScript对象表示法(JavaScript Object Notation) JSON是轻量级的 ...