Determine if a Sudoku is valid, according To:sudoku puzzles-the Rules.
The Sudoku board could be partially filled, where empty cells is filled with the character ‘.‘
.
Problem Solving Ideas:
The legendary Sudoku (nine Gongge) question, honestly traverse three rules:
Java implementations:
Static public Boolean Isvalidsudoku (char[][] board) {for (int i = 0; i < board.length; i++) {hashmap<character, Inte ger> HashMap = new Hashmap<character, integer> (); for (int j = 0; J < Board[0].length; J + +) {if (board[i][j]! = ‘.‘) {if (Hashmap.containskey (Board[i][j])) return False;hashmap.put (Board[i][j], 1);}}} for (int j = 0; J < Board[0].length; J + +) {hashmap<character, integer> HashMap = new Hashmap<character, intege R> (); for (int i = 0; i < board.length; i++) {if (board[i][j]! = '. ') {if (Hashmap.containskey (Board[i][j])) return False;hashmap.put (Board[i][j], 1);}}} for (int i = 0; i < board.length; i + = 3) {for (int j = 0; J < board[0].length; J + = 3) {hashmap< Character, integer> hashmap = new Hashmap<character, integer> (); for (int k = 0; k < 9; k++) {if (board[i + k/ 3][j + k% 3]! = '. ') {if (Hashmap.containskey (board[i + k/3][j + k% 3])) return False;hashmap.put (board[i + k/3][j + k% 3], 1);}}} RetUrn true;}
Java for Leetcode 036 Valid Sudoku