36. Valid Sudoku

LeetCode

2D Array, HashSet link

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public boolean isValidSudoku(char[][] board) {
Set<String> check=new HashSet<>();
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
char ch=board[i][j];
if(ch!='.'){
if(!check.add(ch+"in row"+i)||
!check.add(ch+"in colum"+j)||
!check.add(ch+"in box"+i/3+"-"+j/3)
){
return false;
}
}
}
}
return true;
}
}

0%