You are given n people labeled from knows(a, b) indicating whether person a knows person b. The relationships are also represented by a matrix graph where graph[i][j] == 1 means person i knows person j, and graph[i][j] == 0 means they do not.
A person c is a celebrity if both conditions hold:
For every person i != c, graph[i][c] == 1 (everyone knows c).
For every person i != c, graph[c][i] == 0 (c knows nobody else).
Return the label of the celebrity if one exists, otherwise return
Note: You should solve the problem using the
knowsAPI, and aim to keep the number ofknowscalls within.
Constraints:
n == graph.length == graph[i].length
n
graph[i][j] is
graph[i][i] == 1
You are given n people labeled from knows(a, b) indicating whether person a knows person b. The relationships are also represented by a matrix graph where graph[i][j] == 1 means person i knows person j, and graph[i][j] == 0 means they do not.
A person c is a celebrity if both conditions hold:
For every person i != c, graph[i][c] == 1 (everyone knows c).
For every person i != c, graph[c][i] == 0 (c knows nobody else).
Return the label of the celebrity if one exists, otherwise return
Note: You should solve the problem using the
knowsAPI, and aim to keep the number ofknowscalls within.
Constraints:
n == graph.length == graph[i].length
n
graph[i][j] is
graph[i][i] == 1