# 解锁 Leetcode 新题：寻找明星

Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. 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. Now you want to find out who the celebrity is or verify that there is not one. The only thing you are allowed to do is to ask questions like: “Hi, A. Do you know B?” to get information of whether A knows B. You need to find out the celebrity (or verify there is not one) by asking as few questions as possible (in the asymptotic sense). You are given a helper function bool knows(a, b) which tells you whether A knows B. Implement a function int findCelebrity(n), your function should minimize the number of calls to knows.

### 挖掘隐藏条件

List: P1, P2, P3, P4 一共有四个人， “a->b” 表示 a 认识 b;

• P1->P2, P1->P3, P2->P3, P4->P3, P2->P4: 在这组关系中 P3 就是 celebrity;
• P1->P4, P1->P3, P2->P3, P2->P4: 在这组关系中虽然 P3, P4 都不认识其他人，但是他们都不是 celebrity;

• If Knows (a, b) == true, 说明 a 认识 b, 那么 a 是否还有可能成为 celebrity? 答案是否定的，因为根据 celebrity 的定义, 当 a 认识其他人的时候，a 一定不是 celebrity. 那么 b 有可能么? 答案是有可能。
• If Knows (a, b) == false, 说明 a 不认识 b, 那么 b 可能是 celebrity么? 答案是否定的，因为根据定义，名人被所有人都认识，所以 b 不是名人。

91 篇文章26 人订阅

0 条评论

## 相关文章

### 知识图谱系列 | 知识图谱的前世今生与RDF的实践

【人工智能头条导读】本文是我们知识图谱系列的第二篇文章，希望人工智能头条为大家准备的文章对大家的学习有更多的帮助。

6092

6025

1133

### 自己动手写游戏：坦克撕逼大战

START：最近在公交车上无聊，于是用平板看了看下载的坦克大战的开发教程，于是在晚上回家后花了两天模仿了一个，现在来总结一下。

1936

1483

3874

4099

3747

2803

1054