LeetCode 36 Valid Sudoku
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 其中,未填入 ...
随机推荐
- 获取iis网站信息
1.获取网站的url地址 var ht = GetWebPathAndWebName(""); var rootUrl = ht["webaddr"].ToSt ...
- 在Mac系统中安装及配置Apache Tomcat
1.下载Tomcat http://tomcat.apache.org/download-80.cgi 下载ZIP包,解压后放至任意地址,本例中放在/Users/GuQiang/Tomcat/apac ...
- JavaScript中的类型转换
1.隐式类型转换 ①== 如果相等操作的两个变量不是同一类型,那么相等运算符会尝试进行一些类型转换: 如果一个是null,一个是undefined,则他们相等: 如果一个值是数字,另一个是字符串,先将 ...
- 定位框一闪而过 iOS Swift
需求:获取经纬度. 方案:我自定义了一个类模块CLLocationModule.swift 备注以下代码里 let IS_IOS8 = (UIDevice.currentDevice().system ...
- 【Beta】Scrum09
Info 考试周,暂停工作 时间:2016.12.26 21:35 时长:20min 地点:大运村1号公寓5楼楼道 类型:日常Scrum会议 NXT:2016.12.31 21:30 Task Rep ...
- python之登录小程序
# 登录操作 PassWord_list = [] Reset_pw = '*#*#' def account_login(): if PassWord_list == []: PassWord = ...
- 几种常见的Shell
Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等,习惯上把它们称作一种Shell.我们常说有多少种Shell,其实说的是Shell脚本解释器. bash bash是L ...
- Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor
结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...
- SQLServer------Join的使用方法
参考菜鸟教程网: http://www.runoob.com/sql/sql-join.html select a.Canteen,b.OrderNum,b.CreateTime,c.Name fro ...
- 使用ASP.NET Web API Help Pages 创建在线接口文档
操作步骤 1.新建Web API项目 2.在项目Areas文件夹下找到以下文件,取消注释图中代码. 3.右键解决方案,属性,如图设置. 4.运行程序,点击右上角API 接口列表: 详情-无参数: 详情 ...