File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
+ };
You can’t perform that action at this time.
0 commit comments