We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5f4661e + e01cedc commit d56df68Copy full SHA for d56df68
ONLINE JUDGE/LeetCode/#36 Valid Sudoku.cpp
@@ -0,0 +1,35 @@
1
+class Solution {
2
+public:
3
+ bool isValidSudoku(vector<vector<char>>& board) {
4
+ vector<array<bool,9>> rows(9);
5
+ vector<array<bool,9>> cols(9);
6
+ vector<array<bool,9>> squares(9);
7
+
8
+ for (int y = 0; y < 9 ; ++y) {
9
+ for (int x = 0; x < 9; ++x) {
10
+ if (board[y][x] == '.') continue;
11
12
+ const int current = board[y][x] - '1';
13
14
+ if (rows[y][current]) {
15
+ return false;
16
+ } else {
17
+ rows[y][current] = 1;
18
+ }
19
+ if (cols[x][current]) {
20
21
22
+ cols[x][current] = 1 ;
23
24
25
+ const int sq_index = (y / 3) * 3 + x / 3;
26
+ if (squares[sq_index][current]) {
27
28
29
+ squares[sq_index][current] = 1 ;
30
31
32
33
+ return true;
34
35
+};
0 commit comments