*277. Find the Celebrity
solution
class Solution:
def findCelebrity(self, n: int) -> int:
candidate = 0
for i in range(1, n):
# If the candidate knows person i, then switch candidate to i
if knows(candidate, i):
candidate = i
for i in range(n):
if candidate != i:
if knows(candidate, i) or not knows(i, candidate):
return -1
return candidatePrevious1658. Minimum Operations to Reduce X to ZeroNext*340. Longest Substring with At Most K Distinct Characters
Last updated