public void getNQueens(int [] locations, int row, List<String[]> solutions) {
        if (row == locations.length) {
            String [] solution = new String[row];
            for(int i=0; i<locations.length; i++) {
                StringBuffer tmpRow = new StringBuffer();
                for (int j=0; j<locations.length; j++) {
                    if(j == locations[i]) tmpRow.append("Q");
                    else tmpRow.append(".");
                }
                solution[i] = tmpRow.toString();
            }
            solutions.add(solution);
        }

        for (int i=0; i<locations.length; i++) {
            if (check(locations, row, i)) {
                locations[row] = i;
                getNQueens(locations, row+1, solutions);
            }
        }
    }