Stack problem

as you guys know this is very famous problem of stack
but i have solve this with another approac whithout stack and my code got submitted on gfg …still i am not sure about my code can anyone help me this is my code
int celebrity(vector<vector >& M, int n)
{
vector<vector>g(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(M[i][j]==1){
g[i].push_back(j);
}
}
}
int c=0;
int op=0;
for(int i=0;i<g.size();i++){
if(g[i].size()==0){
c++;
op=i;
}
}
if(c==1){
return op;
}return -1;
}