We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cbf2fe5 commit f4fd475Copy full SHA for f4fd475
0036-valid-sudoku/0036-valid-sudoku.cpp
@@ -0,0 +1,45 @@
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
25
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
37
38
+ boxCheck[board[m][n] - '1'] = true;
39
40
41
42
43
+ return true;
44
45
+};
0 commit comments