public class Solution {
public boolean isValidSudoku(char[][] board) {
HashSet<Character> set = new HashSet<Character>();
for(int i = 0; i < board.length; i++) {
for(int j = 0; j < board[0].length; j++) {
if(set.contains(board[i][j]))
return false;
else if(board[i][j] != '.')
set.add(board[i][j]);
}
set.clear();
}
for(int i = 0; i < board[0].length; i++) {
for(int j = 0; j < board.length; j++) {
if(set.contains(board[j][i]))
return false;
else if(board[j][i] != '.')
set.add(board[j][i]);
}
set.clear();
}
for(int m = 0; m < 3; m++) {
for(int n = 0; n < 3; n++) {
for(int i = 3 * m; i < 3 * m + 3; i++) {
for(int j = 3 * n; j < 3 * n + 3; j++) {
if(set.contains(board[i][j]))
return false;
else if(board[i][j] != '.')
set.add(board[i][j]);
}
}
set.clear();
}
}
return true;
}
}
Determining a number of unique 9x9 is valid. only need toAccording to the following rulesVerify whether the figures have been filled can be effective. Digital1-9Only appear once in each row. Digital1-...
Title and test cases Solution 1 (success, 30ms, medium speed) velocity o (n), the space o (n) in particular a row, a column, a 1-9 find whether squares approach is repeated is added a hashmap, 1-9 as ...
36. Valid Sudoku (Valid Sudoku) Problem Description: Determine whether a 9x9 Sudoku is valid. You only need to verify whether the number you have entered is valid according to the following rules. The...
Determine whether a 9x9 Sudoku is valid. only need toAccording to the following rulesTo verify that the number you have entered is valid. Numbers1-9It can only appear once per line. Numbers1-9It can o...
Title description: The question is relatively simple, it doesn't let you judge whether the current Sudoku has a solution, only judge whether the current filled number meets the regulations. Problem-so...
Title description According to: Sudoku Puzzles-rules to determine whether a Sudoku is valid. The Sudoku board can be partially filled, and empty cells are filled with the characters ‘.’. S...
topic: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must ...
topic Original title link algorithm The requirement of this question is to check whether the nine-square grid given by the question is valid.Only need to detect the number givenThat's it The algorithm...
1. Title description 2. Analysis Judge whether a 9x9 Sudoku is valid. only need toAccording to the following rules, Just verify that the number already filled in is valid. Number1-9It can only appear ...