Among n people, a celebrity is known by everyone but knows nobody. Return the celebrity index or -1. Pattern focus: Adjacency Matrix. The knows relation is naturally represented as a matrix or oracle query.
n = number of people, knows = matrix where knows[i][j] indicates whether i knows j
index of the celebrity, or -1 if none exists
Example 1:
Input:
n = 3 knows = [[0,1,1],[0,0,1],[0,0,0]]
Output:
2
Explanation:
Person 2 is known by everyone and knows nobody.
Example 2:
Input:
n = 2 knows = [[0,1],[0,0]]
Output:
1
Explanation:
Person 1 is the celebrity.