It's very simple column by column tries with DFS. For each column, try every row; for each try point, check if it is safe. When reached level n, print out.

```
List<String[]> list = new ArrayList<String[]>();
public List<String[]> solveNQueens(int n) {
int[][] b = new int[n][n];
dfs(b, 0, n);
return list;
}
public void dfs(int[][] b, int col, int n)
{
if (col == n)
{
list.add(printS(b, n));
return;
}
for (int row = 0; row < n; row ++)
{
if (isSafe(b, row, col, n))
{
b[row][col] = 1;
dfs(b, col + 1, n);
b[row][col] = 0;
}
}
}
public boolean isSafe(int[][] b, int x, int y, int n)
{
for (int i = 0; i < n; i++)
{
if (b[x][i] == 1 || b[i][y] == 1)
{
return false;
}
}
for (int i = 0; i< n; i ++)
for (int j = 0; j < n; j++)
{
if ((i + j == x + y) && b[i][j] == 1)
{
return false;
}
}
for (int i = 0; i < n; i++)
{
if (x-i >=0 && y-i >= 0 && b[x-i][y-i] == 1)
{
return false;
}
if (x+i < n && y+i < n && b[x+i][y+i] == 1)
{
return false;
}
}
return true;
}
```