-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path36.cpp
More file actions
21 lines (21 loc) · 864 Bytes
/
Copy path36.cpp
File metadata and controls
21 lines (21 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
bool isValidSudoku(vector<vector<char>> &board) {
int n = board.size();
vector<vector<bool>> row(9, vector<bool>(9, false)), col(9, vector<bool>(9, false));
vector<vector<vector<bool>>> square(3, vector<vector<bool>>(3, vector<bool>(9, false)));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (board[i][j] == '.')
continue;
if (row[i][board[i][j] - '0' - 1] || col[j][board[i][j] - '0' - 1] ||
square[i / 3][j / 3][board[i][j] - '0' - 1])
return false;
row[i][board[i][j] - '0' - 1] = true;
col[j][board[i][j] - '0' - 1] = true;
square[i / 3][j / 3][board[i][j] - '0' - 1] = true;
}
}
return true;
}
};