C++ use vector


  • 0
    H

    ...
    int totalNQueens(int n) {
    vector<int> a(6n,0);
    vector<vector<int> > res(1,a),tmp;
    int x,y,z;
    for (int i=0; i<n; i++){
    tmp.clear();
    for (int j=0; j<n; j++){
    x=j; y=i+j+n; z=i-j+4
    n;
    for (auto &k:res)
    if (!k[x]&&!k[y]&&!k[z]){
    vector<int> a=k;
    a[x]=a[y]=a[z]=1;
    tmp.push_back(a);
    }
    }
    res=tmp;
    }
    return res.size();
    }
    ...


Log in to reply
 

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