-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36.cpp
37 lines (30 loc) · 1008 Bytes
/
36.cpp
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
#include "leetcode.hpp"
class Solution
{
public:
bool isValidSudoku(vector<vector<char>> &board) {
auto rf = vector<vector<bool>>(9, vector<bool>(9, false));
auto cf = vector<vector<bool>>(9, vector<bool>(9, false));
auto gf = vector<vector<vector<bool>>>(3, vector<vector<bool>>(3, vector<bool>(9, false)));
for (auto i = 0; i < 9; ++i) {
for (auto j = 0; j < 9; ++j) {
const char c = board[i][j];
if (c == '.')
continue;
if (rf[i][c - '1'])
return false;
else
rf[i][c - '1'] = true;
if (cf[j][c - '1'])
return false;
else
cf[j][c - '1'] = true;
if (gf[i / 3][j / 3][c - '1'])
return false;
else
gf[i / 3][j / 3][c - '1'] = true;
}
}
return true;
}
};