Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
find-the-celebrity.py 710 Bytes
Copy Edit Raw Blame History
Allen Liu authored 2018-10-12 01:33 +08:00 . remove sensitive question description
# Time: O(n)
# Space: O(1)
class Solution(object):
def findCelebrity(self, n):
"""
:type n: int
:rtype: int
"""
candidate = 0
# Find the candidate.
for i in xrange(1, n):
if knows(candidate, i): # noqa
candidate = i # All candidates < i are not celebrity candidates.
# Verify the candidate.
for i in xrange(n):
candidate_knows_i = knows(candidate, i) # noqa
i_knows_candidate = knows(i, candidate) # noqa
if i != candidate and (candidate_knows_i or
not i_knows_candidate):
return -1
return candidate
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search