Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'
.
A partially filled sudoku which is valid.
public class Solution { public boolean isValidSudoku(char[][] board) { // Start typing your Java solution below // DO NOT write main() function for(int i = 0 ; i < 9 ;i++){ for(int j = 0 ; j<9 ; j++){ if(board[i][j] !='.' &&!isValid(board,i,j)) return false; } } return true; } public boolean isValid(char[][] board,int i, int j){ for(int coloum = 0 ; coloum < 9 ; coloum++){ if(coloum!= j && board[i][j] == board[i][coloum]) return false; } for(int row = 0 ; row < 9 ; row++){ if(row != i && board[row][j] == board[i][j]) return false; } for (int row = (i / 3) * 3; row < (i / 3) * 3 + 3; row++){ for (int col = (j / 3) * 3; col < (j / 3) * 3 + 3; col++){ if(col!=j&&row!=i&&board[row][col] == board[i][j]) return false; } } return true; } }