矩阵
This commit is contained in:
parent
0bf945aa89
commit
06c7a0c06b
32
算法面试题/矩阵.cpp
Normal file
32
算法面试题/矩阵.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "¾ØÕó.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
bool ¾ØÕó::isValidSudoku(vector<vector<char>>& board) {
|
||||
if (board.empty() || board.size() != 9 || board[0].size() != 9)\
|
||||
return false;
|
||||
|
||||
set<char> row, col, pos;
|
||||
for (int i = 0; i < board.size(); i++) {
|
||||
for (int j = 0; j < board[0].size(); j++) {
|
||||
if (board[i][j] == '.')
|
||||
continue;
|
||||
int value = i * 10 + board[i][j];
|
||||
if (row.count(value)) {
|
||||
return false;
|
||||
}
|
||||
row.insert(value);
|
||||
|
||||
value = j * 10 + board[i][j];
|
||||
if (col.count(value))
|
||||
return false;
|
||||
col.insert(value);
|
||||
|
||||
value = ((i / 3) * 3 + (j / 3)) * 10 + board[i][j];
|
||||
if (pos.count(value))
|
||||
return false;
|
||||
pos.insert(value);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
12
算法面试题/矩阵.h
Normal file
12
算法面试题/矩阵.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class 矩阵 {
|
||||
public:
|
||||
// 36. 有效的数独
|
||||
bool isValidSudoku(vector<vector<char>>& board);
|
||||
};
|
||||
|
@ -145,6 +145,7 @@
|
||||
<ClCompile Include="图.cpp" />
|
||||
<ClCompile Include="数组和字符串.cpp" />
|
||||
<ClCompile Include="栈.cpp" />
|
||||
<ClCompile Include="矩阵.cpp" />
|
||||
<ClCompile Include="算法面试题.cpp" />
|
||||
<ClCompile Include="链表.cpp" />
|
||||
</ItemGroup>
|
||||
@ -155,6 +156,7 @@
|
||||
<ClInclude Include="图.h" />
|
||||
<ClInclude Include="数组和字符串.h" />
|
||||
<ClInclude Include="栈.h" />
|
||||
<ClInclude Include="矩阵.h" />
|
||||
<ClInclude Include="链表.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -39,6 +39,9 @@
|
||||
<ClCompile Include="链表.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="矩阵.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Solution.h">
|
||||
@ -62,5 +65,8 @@
|
||||
<ClInclude Include="链表.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="矩阵.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user