Skip to content

Commit f4fd475

Browse files
committed
Time: 41 ms (65.20%), Space: 18.1 MB (72.48%) - LeetHub
1 parent cbf2fe5 commit f4fd475

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class Solution {
2+
public:
3+
bool isValidSudoku(vector<vector<char>> const & board)
4+
{
5+
for (int i = 0; i < 9; i++)
6+
{
7+
bool rowCheck[9] = {};
8+
bool colCheck[9] = {};
9+
bool boxCheck[9] = {};
10+
11+
for (int j = 0; j < 9; j++)
12+
{
13+
if (board[i][j] != '.')
14+
{
15+
if (rowCheck[board[i][j] - '1'])
16+
return false;
17+
else
18+
rowCheck[board[i][j] - '1'] = true;
19+
}
20+
21+
if (board[j][i] != '.')
22+
{
23+
if (colCheck[board[j][i] - '1'])
24+
return false;
25+
else
26+
colCheck[board[j][i] - '1'] = true;
27+
}
28+
29+
30+
int m = i / 3 * 3 + j / 3;
31+
int n = i % 3 * 3 + j % 3;
32+
33+
if (board[m][n] != '.')
34+
{
35+
if (boxCheck[board[m][n] - '1'])
36+
return false;
37+
else
38+
boxCheck[board[m][n] - '1'] = true;
39+
}
40+
41+
}
42+
}
43+
return true;
44+
}
45+
};

0 commit comments

Comments
 (0)