Valid Sudoku (leetcode)
user_2792839298
java
2 years ago
496 B
3
Indexable
Never
public boolean isValidSudoku(char[][] board) { Set<String> set = new HashSet<>(); for(int i=0; i<board.length; i++){ for(int j=0; j<board[0].length; j++){ char ch = board[i][j]; if(ch!='.'){ if(!set.add("row" + i + ch) || !set.add("col" + j + ch) || !set.add("grid" + ch + i/3 + j/3)){ return false; } } } } return true; }