-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst3.cpp
63 lines (59 loc) · 1.2 KB
/
st3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
//Function to find if there is a celebrity in the party or not.
int celebrity(vector < vector < int > > & M, int n) {
// code here
stack < int > x;
for (int i = 0; i < n; i++) {
if (M[0][i] == 1) {
x.push(i);
}
}
if (x.size() == 0) {
int x = 2 ;
for (int i = 1 ; i < n ; i++)
{
if(M[i][0]!=1)
{
x = 1 ;
break ;
}
}
if(x==2)
{
return 0 ;
}
return -1 ;
}
// cout<<"ok"<<endl ;
int p = x.size() , q=-1;
for(int i = 0 ; i < p ; i++ )
{
if(M[x.top()][0]==0)
{
q = x.top() ;
break ;
}
x.pop() ;
}
// cout<<q<<endl ;
for(int i = 0 ; i < n ; i++)
{
if(M[q][i]!=0)
{
return -1 ;
}
}
return q ;
}
};
int main()
{
int n = 2 ;
vector<vector<int>> x = {{0,1,0},{0,0,0},{0,1,0}} ;
Solution s ;
cout<<s.celebrity(x,n) ;
return 0 ;
}