class Solution {
public void solveSudoku(char[][] board) {
//最骚的一点:给递归函数一个返回值 直接调用 太帅了
bp(board);
}
private boolean bp(char[][] board){
for(int i =0;i<9;i++){
for(int j =0; j<9 ;j++){
if(board[i][j] != '.') continue;
for(char z = '1';z<='9';z++){
if(isValid(i,j,z,board)){
//进入递归
board[i][j] = z;
if(bp(board)) return true;
board[i][j] = '.';
}
}
return false;
}
}
return true;
}
private boolean isValid(int r,int c,char v,char[][] board){
for(int i =0;i<9;i++){
if(board[r][i] == v) return false;
if(board[i][c] == v) return false;
}
int i = (r/3)*3;
int j = (c/3)*3;
for(int a = i;a<i+3;a++){
for(int b = j;b<j+3;b++){
if(board[a][b] == v) return false;
}
}
return true;
}
}