leetcode-277-Find the Celebrity

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zem_nezer/article/details/86677284

Error:
do not know how to do: definition of celebrity:
- n - 1 knows him
- him do not know n - 1

In order word, if know(A -> B) == true, it means A must not be the celebrity, B may be the celebrity; if know(A -> B) == false, it means A may be the celebrity, B must not be the celebrity.

So first we get the last celebrity which know(A -> B) == false, then check if current celebrity know any of them. O(N) time complexity

猜你喜欢

转载自blog.csdn.net/zem_nezer/article/details/86677284