public boolean isValidSudoku(char[][] board) {
int size = board.length;
for(int i = 0; i < size; i++)
{
boolean b1[] = new boolean[size];
for(int j = 0; j < size; j++)
{
if(board[i][j] != '.')
{
int diff = board[i][j]  '1';
if(b1[diff])
return false;
b1[diff] = true;
}
}
boolean b2[] = new boolean[size];
for(int k = 0; k < size; k++)
{
if(board[k][i] != '.')
{
int diff = board[k][i]  '1';
if(b2[diff])
return false;
b2[diff] = true;
}
}
boolean b3[] = new boolean[size];
for(int m = 0; m < size; m++)
{
int x = m / 3 + (i / 3) * 3;
int y = m % 3 + (i % 3) * 3;
if(board[x][y] != '.')
{
int diff = board[x][y]  '1';
if(b3[diff])
return false;
b3[diff] = true;
}
}
}
return true;
}
Fast Java Implementation by Array rathe than Set


Your code is clean and awesome. I add some comments to it so it would be more understandable.
public boolean isValidSudokuWithArrays(char[][] board) { int size = board.length; for (int i = 0; i < size; i++) { // Check rows boolean[] row = new boolean[size]; for (int j = 0; j < size; j++) { if (board[i][j] != '.') { // The number in board[i][j] is 19, convert it to 08 so that it can be filled into the array int diff = board[i][j]  '1'; if (row[diff]) return false; row[diff] = true; } } // Check columns boolean[] col = new boolean[size]; for (int k = 0; k < size; k++) { if (board[k][i] != '.') { int diff = board[k][i]  '1'; if (col[diff]) return false; col[diff] = true; } } // Check the inner boxes boolean[] box = new boolean[size]; for (int m = 0; m < size; m++) { int x = m / 3 + (i / 3) * 3; int y = m % 3 + (i % 3) * 3; if (board[x][y] != '.') { int diff = board[x][y]  '1'; if (box[diff]) return false; box[diff] = true; } } } return true; }