Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-08-20_23-54-22.png
60.8 KB
#medium
#N36. Valid Sudoku
problem link
#solution
class Solution {
public boolean isValidSudoku(char[][] board) {
boolean case1=true, case2=true, case3=true;
Set<Character> set1 = new HashSet<>();
Set<Character> set2 = new HashSet<>();
Set<Character> set3 = new HashSet<>();
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
if(board[i][j] != '.' && !set1.add(board[i][j])) return false;
if(board[j][i] != '.' && !set2.add(board[j][i])) return false;
if(board[3*(i/3)+j/3][3*(i%3)+j%3] != '.' &&
!set3.add(board[3*(i/3)+j/3][3*(i%3)+j%3])) return false;
}
set1 = new HashSet<>();
set2 = new HashSet<>();
set3 = new HashSet<>();
}
return true;
}
}
🔥2