The Sudoku board could be partially filled, where empty cells are filled with the character
'.'
.
A partially filled sudoku which is valid.
Note:
A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | bool isValidSudoku(char** board, int boardRowSize, int boardColSize) { for(int i=0;i<boardRowSize;i++){ for(int j=0;j<boardColSize;j++){ if(board[i][j]!='.'){ int counter=0,target=board[i][j]; for(int r=0;r<boardColSize;r++)if(board[r][j]==target)counter++; if(counter!=1)return false; for(int c=0;c<boardRowSize;c++)if(board[i][c]==target)counter++; if(counter!=2)return false; for(int r=(i/3)*3;r<(i/3)*3+3;r++){ for(int c=(j/3)*3;c<(j/3)*3+3;c++){ if(board[r][c]==target)counter++; } } if(counter!=3)return false; } } } return true; } |
沒有留言:
張貼留言