Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Logic is :there can be only on celebrity possible,because for being another celebrity,first celebrity must know the other celebrity
- and if first celebrity knows the second celebrity,then first celebrity can't be celebrity because he knows someone else.
- so using stack,i found that one probable celebrity.
- */
- class Solution:
- def celebrity(self, mat):
- st=[i for i in range(len(mat))]
- while len(st)>1:
- a,b=st.pop(),st.pop()
- if mat[a][b]==1:
- st.append(b)
- else:
- st.append(a)
- k=st[-1]
- for i in range(len(mat)):
- if k==i:
- continue;
- if mat[i][k]==0 or mat[k][i]==1:
- return -1
- return k
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement