```
public class Solution {
public boolean isValidSudoku(char[][] board) {
HashSet<Character> set= new HashSet<>();
int row=0;
int col=0;
for(int i=0;i<9;i++){
//for rows
for(int j=0;j<9;j++){
if(board[i][j]=='.')
continue;
if(set.contains(board[i][j]))
return false;
else
set.add(board[i][j]);
}
set.clear();
//for cols
for(int k=0;k<9;k++){
if(board[k][i]=='.')
continue;
if(set.contains(board[k][i]))
return false;
else
set.add(board[k][i]);
}
set.clear();
//for box
row = i%3==0?i:row;
col = i%3==0?0:col+3;
for(int r=row;r<row+3;r++){
for(int c=col;c<col+3;c++){
if(board[r][c]=='.')
continue;
if(set.contains(board[r][c]))
return false;
else
set.add(board[r][c]);
}
}
set.clear();
}
return true;
}
}
```