-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36.txt
27 lines (27 loc) · 954 Bytes
/
36.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public boolean isValidSudoku(char[][] board) {
HashSet<Character> row = new HashSet();
HashSet<Character> column = new HashSet();
HashSet<Character> grid = new HashSet();
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
if(board[i][j] != '.') {
if(!row.add(board[i][j]))
return false;
}
if(board[j][i] != '.') {
if(!column.add(board[j][i]))
return false;
}
int RowIndex = 3*(i/3);
int ColIndex = 3*(i%3);
if(board[RowIndex + j/3][ColIndex + j%3]!='.' && !grid.add(board[RowIndex + j/3][ColIndex + j%3]))
return false;
}
row.clear();
column.clear();
grid.clear();
}
return true;
}
}