You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[Leetcode-652](https://leetcode.com/problems/find-duplicate-subtrees/)| Find Duplicate Subtrees |[c++](./leetcode/652.find-duplicate-subtrees.cpp)| Other |\-|\-| - |
961
962
|[Leetcode-366](https://leetcode.com/problems/find-leaves-of-binary-tree/)| Find Leaves Of Binary Tree |[c++](./leetcode/366.find-leaves-of-binary-tree.cpp), [python3](./leetcode/366.find-leaves-of-binary-tree.py)| Other |\-|\-| - |
962
963
|[Leetcode-724](https://leetcode.com/problems/find-pivot-index/)| Find Pivot Index |[c++](./leetcode/724.find-pivot-index.cpp)| Other |\-|\-| - |
963
-
|[Leetcode-277](https://leetcode.com/problems/find-the-celebrity/)| Find The Celebrity |[c++](./leetcode/277.find-the-celebrity.cpp), [python3](./leetcode/277.find-the-celebrity.py)| Other |\-|\-| - |
964
964
|[Leetcode-41](https://leetcode.com/problems/first-missing-positive/)| First Missing Positive |[python3](./leetcode/41.first-missing-positive.py)| Other |\-|\-| - |
965
965
|[Leetcode-387](https://leetcode.com/problems/first-unique-character-in-a-string/)| First Unique Character In A String |[c++](./leetcode/387.first-unique-character-in-a-string.cpp), [python3](./leetcode/387.first-unique-character-in-a-string.py)| Other |\-|\-| - |
966
966
|[Leetcode-251](https://leetcode.com/problems/flatten-2d-vector/)| Flatten 2D Vector |[python3](./leetcode/251.flatten-2d-vector.py)| Other |\-|\-| - |
// Suppose you are at a party with `n` people (labeled from `0` to `n - 1`) and among them, there may exist one celebrity.
8
+
// The definition of a celebrity is that all the other `n - 1` people know him/her but he/she does not know any of them.
9
+
//
10
+
// Now you want to find out who the celebrity is or verify that there is not one.
11
+
// The only thing you are allowed to do is to ask questions like: "Hi, A.
12
+
// Do you know B?" to get information of whether A knows B.
13
+
// You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).
14
+
//
15
+
// You are given a helper function `bool knows(a, b)` which tells you whether A knows B.
16
+
// Implement a function `int findCelebrity(n)`, your function should minimize the number of calls to `knows`.
17
+
//
18
+
// **Example1**
19
+
// ```
20
+
// Input:
21
+
// 2 // next n * (n - 1) lines
22
+
// 0 knows 1
23
+
// 1 does not know 0
24
+
// Output: 1
25
+
// Explanation:
26
+
// Everyone knows 1,and 1 knows no one.
27
+
// ```
28
+
// **Example2**
29
+
// ```
30
+
// Input:
31
+
// 3 // next n * (n - 1) lines
32
+
// 0 does not know 1
33
+
// 0 does not know 2
34
+
// 1 knows 0
35
+
// 1 does not know 2
36
+
// 2 knows 0
37
+
// 2 knows 1
38
+
// Output: 0
39
+
// Explanation:
40
+
// Everyone knows 0,and 0 knows no one.
41
+
// 0 does not know 1,and 1 knows 0.
42
+
// 2 knows everyone,but 1 does not know 2.
43
+
// ```
44
+
//
45
+
// There will be exactly one celebrity if he/she is in the party. Return the celebrity's label if there is a celebrity in the party. If there is no celebrity, return `-1`.
# Suppose you are at a party with `n` people (labeled from `0` to `n - 1`) and among them, there may exist one celebrity.
8
+
# The definition of a celebrity is that all the other `n - 1` people know him/her but he/she does not know any of them.
9
+
#
10
+
# Now you want to find out who the celebrity is or verify that there is not one.
11
+
# The only thing you are allowed to do is to ask questions like: "Hi, A.
12
+
# Do you know B?" to get information of whether A knows B.
13
+
# You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense).
14
+
#
15
+
# You are given a helper function `bool knows(a, b)` which tells you whether A knows B.
16
+
# Implement a function `int findCelebrity(n)`, your function should minimize the number of calls to `knows`.
17
+
#
18
+
# **Example1**
19
+
# ```
20
+
# Input:
21
+
# 2 // next n * (n - 1) lines
22
+
# 0 knows 1
23
+
# 1 does not know 0
24
+
# Output: 1
25
+
# Explanation:
26
+
# Everyone knows 1,and 1 knows no one.
27
+
# ```
28
+
# **Example2**
29
+
# ```
30
+
# Input:
31
+
# 3 // next n * (n - 1) lines
32
+
# 0 does not know 1
33
+
# 0 does not know 2
34
+
# 1 knows 0
35
+
# 1 does not know 2
36
+
# 2 knows 0
37
+
# 2 knows 1
38
+
# Output: 0
39
+
# Explanation:
40
+
# Everyone knows 0,and 0 knows no one.
41
+
# 0 does not know 1,and 1 knows 0.
42
+
# 2 knows everyone,but 1 does not know 2.
43
+
# ```
44
+
#
45
+
# There will be exactly one celebrity if he/she is in the party. Return the celebrity's label if there is a celebrity in the party. If there is no celebrity, return `-1`.
0 commit comments