class Solution {
public boolean isValidSudoku(char[][] board) {
Map<Integer, Integer>[] row = new HashMap[9];
Map<Integer, Integer>[] col = new HashMap[9];
Map<Integer, Integer>[] table = new HashMap[9];
for (int i = 0; i < 9; i++) {
row[i] = new HashMap<Integer, Integer>();
col[i] = new HashMap<Integer, Integer>();
table[i] = new HashMap<Integer, Integer>();
}
int tableNum = 0, baseTableNum = 0;
for (int i = 0; i < board.length; i++) {
if (i != 0 && i % 3 == 0) baseTableNum += 3;
int k = 0;
for (int j = 0; j < board.length; j++) {
if(j!=0 && j%3==0) k++;
tableNum = baseTableNum + k;
if (table[tableNum].containsKey(board[i][j] - '0') && board[i][j]!='.') return false;
else table[tableNum].put(board[i][j] - '0', 1);
if (row[i].containsKey(board[i][j] - '0') && board[i][j]!='.') return false;
else row[i].put(board[i][j] - '0', 1);
if (col[j].containsKey(board[i][j] - '0') && board[i][j]!='.') return false;
else col[j].put(board[i][j] - '0', 1);
System.out.println(tableNum);
}
}
return true;
}
}