• ``````bool check(vector<int> &board, int cur){
for(int i = 0; i < cur; ++i)
if(board[i] == board[cur] || (abs(board[i] - board[cur]) == cur - i))
return false;
return true;
}

void print(vector<int> &board, vector<vector<string> > &result){
int N = board.size();
vector<string> pic(N, string(N,'.'));
for(int i = 0; i < N; ++i)
pic[i][board[i]] = 'Q';
result.push_back(pic);
}

void place(int cur, vector<int> &board, vector<vector<string> > &result){
int N = board.size();
//bottom condition
if(cur == N)
print(board, result);

//
for(int pos = 0; pos < N; ++pos){
board[cur] = pos;
if(check(board, cur) == true)
place(cur + 1, board, result);
}
}

class Solution {
public:
vector<vector<string> > solveNQueens(int n) {
vector<int> board(n, -1);
vector<vector<string> > result;
place(0, board, result);
return result;
}
};
``````

My solution is the classical DFS solution. I dont think I am wrong, and I want to know what happened? Thx.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.