当前位置:网站首页>Leetcode 36. Effective Sudoku (yes, once)
Leetcode 36. Effective Sudoku (yes, once)
2022-06-28 20:21:00 【I'm not xiaohaiwa~~~~】

Please judge a 9 x 9 Is the Sudoku effective . It only needs According to the following rules , Verify that the numbers you have filled are valid .
- Numbers 1-9 Only once in a row .
- Numbers 1-9 It can only appear once in each column .
- Numbers 1-9 Separated by thick solid lines in each 3x3 Only once in the palace .( Please refer to the example figure )
Be careful :
- An effective Sudoku ( Part has been filled in ) Not necessarily solvable .
- Just follow the above rules , Verify that the numbers you have filled are valid .
- Blank space ‘.’ Express .
Example 1:

Input :board =
[["5","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
Output :true
Example 2:
Input :board =
[["8","3",".",".","7",".",".",".","."]
,["6",".",".","1","9","5",".",".","."]
,[".","9","8",".",".",".",".","6","."]
,["8",".",".",".","6",".",".",".","3"]
,["4",".",".","8",".","3",".",".","1"]
,["7",".",".",".","2",".",".",".","6"]
,[".","6",".",".",".",".","2","8","."]
,[".",".",".","4","1","9",".",".","5"]
,[".",".",".",".","8",".",".","7","9"]]
Output :false
explain : Except for the first number in the first line from 5 Change it to 8 outside , The other numbers in the space are the same as Example 1 identical . But because of the 3x3 There are two in the palace 8 There is , So this Sudoku is invalid .
Tips :
- board.length == 9
- board[i].length == 9
- board[i][j] It's a number (1-9) perhaps ‘.’
Main idea :map
Code:
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
map<char,int>mymap;
pair<map<char, int>::iterator, bool> ret;
for(int j=0;j<board[0].size();j++)
{
for(int i=0;i<board.size();i++)
{
vector<char>sub=board[i];
if(board[i][j]=='.')
continue;
ret=mymap.insert(pair<char,int>(board[i][j],0));
if(!ret.second)
return false;
cout<<board[i][j]<<endl;
}
mymap.clear();
}
mymap.clear();
for(int i=0;i<board.size();i++)
{
vector<char>sub=board[i];
for(int j=0;j<sub.size();j++)
{
if(sub[j]=='.')
continue;
ret=mymap.insert(pair<char,int>(sub[j],0));
if(!ret.second)
return false;
}
mymap.clear();
}
mymap.clear();
cout<<"++++"<<endl;
int row=0;
int col=0;
do
{
for(int i=row;i<row+3;i++)
{
vector<char>sub=board[i];
for(int j=col;j<col+3;j++)
{
if(sub[j]=='.')
continue;
ret=mymap.insert(pair<char,int>(sub[j],0));
if(!ret.second)
return false;
}
}
col+=3;
mymap.clear();
if(col==9)
{
col=0;
row+=3;
cout<<"row="<<row<<endl;
}
if(row==9)
{
break;
}
}while(1);
return true;
}
};
边栏推荐
- 2. 整合 Filter
- UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation
- Windows 64 bit download install my SQL
- ROS中quaternion四元数和欧拉角转换
- [learning notes] cluster analysis
- TcWind 模式設定
- Comparisonchain file name sort
- 30讲 线性代数 第四讲 线性方程组
- How to obtain the coordinates of the aircraft passing through both ends of the radar
- Class loading mechanism and object creation
猜你喜欢

Jenkins pipeline's handling of job parameters

Analysis of all knowledge points of TCP protocol in network planning

SQL server2019 create a new SQL server authentication user name and log in

C#应用程序界面开发基础——窗体控制

UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation

【毕业季·进击的技术er】努力只能及格,拼命才能优秀!

Data standardization processing

2022 tea master (intermediate) examination simulated 100 questions and simulated examination

Severity code description project file line suppress status error lnk2038 detected a mismatch of "runtimelibrary": the value "md\u dynamicrelease" does not match the value "mdd\u dynamicde"

Markdown mermaid種草(1)_ mermaid簡介
随机推荐
【学习笔记】因子分析
Compression and decompression commands
各种类型长
数据标准化处理
SaaS sales upgrade under the new situation | tob Master Course
QSP读取标签配置错误问题
Racher add / delete node
head、tail查看文件
Data standardization processing
Markdown Mermaid Grass (1) Introduction à Mermaid
rsync远程同步
ref属性,props配置,mixin混入,插件,scoped样式
Ali open source (easyexcel)
核芯物联蓝牙aoa定位系统服务器配置估算
还在付费下论文吗?快来跟我一起白piao知网
蓝桥杯 历届试题 蚂蚁感冒
risc-v指令集
TcWind 模式設定
oracle delete误删除表数据后如何恢复
Quaternion quaternion and Euler angle transformation in ROS