-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path036.ValidSudoku.cpp
More file actions
43 lines (40 loc) · 1.45 KB
/
036.ValidSudoku.cpp
File metadata and controls
43 lines (40 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Question:
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.
*/
//Code:
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board) {
std::map<int, bool> rows[9]; //The array of map
std::map<int, bool> colms[9]; //The array of map
std::map<int, bool> grids[9]; //The array of map
for(int i=0;i<board.size();i++) {
for(int j=0;j<board[0].size();j++) {
if(board[i][j] != '.') {
if(rows[i][board[i][j]] == false)
{
rows[i][board[i][j]] = true;
}
else {return false;}
if(colms[j][board[i][j]] == false)
{
colms[j][board[i][j]] = true;
}
else {return false;}
int p = i/3 * 3 + j/3;
if(grids[p][board[i][j]] == false)
{
grids[p][board[i][j]] = true;
}
else {return false;}
}
}
}
return true;
}
};