forked from IIdroyII/cpp_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid_sudoku.cpp
More file actions
23 lines (22 loc) · 746 Bytes
/
Copy pathvalid_sudoku.cpp
File metadata and controls
23 lines (22 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
bool isValidSudoku(vector<vector<char>>& b) {
vector<unordered_set<char>> row(9);
vector<unordered_set<char>> col(9);
vector<unordered_set<char>> box(9);
for(int i=0 ; i<9 ; i ++){
for(int j=0 ; j<9 ; j++){
char val=b[i][j];
if(val=='.')continue;
if(row[i].find(val)!=row[i].end())return false;
row[i].insert(val);
if(col[j].find(val)!=col[j].end())return false;
col[j].insert(val);
int id=(i/3)*3+j/3;
if(box[id].find(val)!=box[id].end())return false;
box[id].insert(val);
}
}
return true;
}
};