-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidsudoku.cpp
71 lines (68 loc) · 1.68 KB
/
validsudoku.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
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
using namespace std;
class Solution
{
public:
int isValidSudoku(vector<vector<char>> &board)
{
set<int> s;
s.clear();
for (int row = 0; row < 9; row++)
{
for (int col = 0; col < 9; col++)
{
if (board[row][col] != '.')
{
if (s.find(board[row][col]) != s.end())
return 1;
else
s.insert(board[row][col]);
}
}
s.clear();
}
for (int col = 0; col < 9; col++)
{
for (int row = 0; row < 9; row++)
{
if (board[row][col] != '.')
{
if (s.find(board[row][col]) != s.end())
return 2;
else
s.insert(board[row][col]);
}
}
s.clear();
}
for (int row = 0; row < 9; row += 3)
{
for (int col = 0; col < 9; col += 3)
{
for (int i = row; i < row + 3; i++)
{
for (int j = col; j < col + 3; j++)
{
if (s.find(board[i][j]) != s.end())
return 3;
else
s.insert(board[i][j]);
}
}
}
s.clear();
}
return 4;
}
};
int main()
{
vector<vector<char>> vec;
vector<char> tmp={};
return 0;
}