-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path36.cpp
More file actions
64 lines (52 loc) · 1.45 KB
/
36.cpp
File metadata and controls
64 lines (52 loc) · 1.45 KB
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
#include <stdio.h>
#include <unordered_map>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
bool isValidSudoku(vector<vector<char>> &board)
{
unordered_map<int, int> hashmap_row;
unordered_map<int, int> hashmap_columns;
unordered_set<char> box[3][3];
for (int i = 0; i < board.size(); i++)
{
int r = i / 3;
for (int j = 0; j < board[i].size(); j++)
{
int c = j / 3;
if (hashmap_row[board[i][j]] ||
hashmap_columns[board[j][i]] ||
box[r][c].count(board[i][j]))
{
return false;
}
if (board[i][j] != '.')
{
hashmap_row[board[i][j]]++;
box[r][c].insert(board[i][j]);
}
if (board[j][i] != '.')
hashmap_columns[board[j][i]]++;
}
hashmap_row.clear();
hashmap_columns.clear();
}
vector<int> output;
return true;
}
int main()
{
vector<vector<char>> nums =
{{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
{'2', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '1', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '2', '.', '6', '.', '.', '.', '3'},
{'7', '.', '.', '9', '.', '3', '.', '.', '1'},
{'4', '.', '.', '.', '.', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}};
bool output = isValidSudoku(nums);
printf("%d\n", output);
return 0;
}