Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e743dc3

Browse files
Day 5 Solutions
1 parent 4730beb commit e743dc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Day 5/36. Valid Sudoku.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
bool isValidSudoku(vector<vector<char>>& board) {
4+
// created 3 different hashsets for rows, cols and sub-grids
5+
6+
unordered_set<char> col[9];
7+
unordered_set<char> row[9];
8+
unordered_set<char> sub_grid[3][3];
9+
10+
for(int i=0;i<9;i++){
11+
for(int j=0;j<9;j++){
12+
char found=board[i][j];
13+
14+
// if the position is not blank , we have to check
15+
if(found != '.'){
16+
if(row[i].count(found) || col[j].count(found) || sub_grid[i/3][j/3].count(found))
17+
return false;
18+
}
19+
20+
row[i].insert(found);
21+
col[j].insert(found);
22+
sub_grid[i/3][j/3].insert(found);
23+
}
24+
}
25+
return true;
26+
}
27+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /