/** 37. Sudoku Solver * 2015.12.13 by Mingyang * 1. Length standard: None * 2. Optional range: All the wood is worth the point, pick a number from 1 to 9 * 3. Take a step forward: if put in is validate, then Put * 4. Take a step back: if you put it in and the back is false, change the point back to * 5. Special case: No * 6. On repetition: none * The IsValid of this topic is difficult * row = I/3 * 3; Row < I/3 * 3 + 3*/ Public voidSolvesudoku (Char[] board) { if(board = =NULL|| Board.length = = 0) return; Helper (board); } Private BooleanHelperChar[] board) { for(inti = 0; i < board.length; i++) { for(intj = 0; J < Board[0].length; J + +) { if(Board[i][j] = = '. ') { for(Charnum = ' 1 '; Num <= ' 9 '; num++) {//Try if(isValid (board, I, J, num)) {Board[i][j]=num; if(Helper (board))//this point is a temporary fit, so go to the next level . return true; ElseBoard[i][j]= '. ';// Fallback } } return false; } } } return true; } Private BooleanIsValid (Char[] board,intIintJCharc) {//Check Column for(introw = 0; Row < 9; row++) if(Board[row][j] = =c)return false; //Check Row for(intcol = 0; Col < 9; col++) if(Board[i][col] = =c)return false; //Check Block for(introw = I/3 * 3; Row < I/3 * 3 + 3; row++) for(intCol = J/3 * 3; Col < J/3 * 3 + 3; col++) if(Board[row][col] = =c)return false; return true; }
Panax Sudoku Solver