Hope this helps, #memenation


#1
public class Sudoku {
public void solveSudoku(ArrayList<ArrayList<Character>> a) {
    int ss = sudoku(a);
    /*printList(a);*/
}

/*private void printList(ArrayList<ArrayList<Character>> a) {
    for(int i=0; i<a.size(); i++){
        System.out.println(a.get(i));
    }
}*/

private static int sudoku(ArrayList<ArrayList<Character>> a) {

    int row=-1, col=-1;
    for(int r=0; r<a.size(); r++){
        for(int c=0; c<a.size(); c++){
            if(a.get(r).get(c)=='.'){
                row = r;
                col = c;
            }
        }
    }
    if(row==-1){
        return 1;
    }

    for(int i=1; i<=9; i++){
        if(safe(a, i, row, col)==1){
            a.get(row).set(col, (char)(48+i));
            if(sudoku(a)==1){
                return 1;
            }
            else {
                a.get(row).set(col,'.');
            }
        }
    }

    return -1;
}

private static int safe(ArrayList<ArrayList<Character>> a, int i, int row, int col) {
    char c = (char)(48+i);

    for(int x=0; x<a.size(); x++){
        if(c == a.get(x).get(col)){
            return -1;
        }
    }

    for(int x=0; x<a.size(); x++){
        if(c == a.get(row).get(x)){
            return -1;
        }
    }

    int minr = (row/3)*3;
    int maxr = minr+3;

    int minc = (col/3)*3;
    int maxc = minc+3;

    for(int x=minr; x<maxr; x++){
        for(int y=minc; y<maxc; y++){
            if(c == a.get(x).get(y)){
                return -1;
            }
        }
    }

    return 1;
}

}