-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleet_0036_check_sudoku___Brute.cpp
80 lines (76 loc) · 2.28 KB
/
leet_0036_check_sudoku___Brute.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& board)
{
vector<int> d;
int r, c, rr, cc;
int n;
for (vector<char> R: board)
{
d = {};
for (char c: R)
{
if (!isdot(c))
{
if (find(d.begin(), d.end(), c) != d.end())
{
// cout << "1" << endl;
return false;
}
d.push_back(c);
}
}
}
c = -1;
while (++c < 9)
{
d = {};
r = -1;
while (++r < 9)
{
n = board[r][c];
if (!isdot(n))
{
if (find(d.begin(), d.end(), n) != d.end())
{
// cout << "2" << endl;
return false;
}
d.push_back(n);
}
}
}
r = -1;
while (++r < 3)
{
c = -1;
while (++c < 3)
{
d = {};
rr = r * 3 - 1;
while (++rr < r * 3 + 3)
{
cc = c * 3 - 1;
while (++cc < c * 3 + 3)
{
n = board[rr][cc];
if (!isdot(n))
{
if (find(d.begin(), d.end(), n) != d.end())
{
// cout << "3" << endl;
return false;
}
d.push_back(n);
}
}
}
}
}
return true;
}
int isdot(char c) { return (c == '.'); }
};
/*
[[".",".","4",".",".",".","6","3","."],[".",".",".",".",".",".",".",".","."],["5",".",".",".",".",".",".","9","."],[".",".",".","5","6",".",".",".","."],["4",".","3",".",".",".",".",".","1"],[".",".",".","7",".",".",".",".","."],[".",".",".","5",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]
*/