Skip to content

277. Find the Celebrity #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tech-cow opened this issue Aug 5, 2019 · 0 comments
Closed

277. Find the Celebrity #58

tech-cow opened this issue Aug 5, 2019 · 0 comments

Comments

@tech-cow
Copy link
Owner

tech-cow commented Aug 5, 2019

第一刷记录:

失败: 对input没搞清楚,题目的Example是graph,所以很顺其自然的想到创建Graph上面,我思路是创建一个graph,然后寻找没有neighbor的node,和下面的方法high level上没有太大的出路

class Solution(object):
    def findCelebrity(self, n):
        celeb = 0
        
        for i in range(1, n):
            if knows(celeb, i):
                celeb = i
            
        for i in range(n):
            if i == celeb: continue
            if knows(celeb, i): return -1
            if not knows(i, celeb): return -1
        
        return celeb
@tech-cow tech-cow added the Array label Aug 5, 2019
@tech-cow tech-cow closed this as completed Aug 5, 2019
@tech-cow tech-cow changed the title [Array] 277. Find the Celebrity 277. Find the Celebrity Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant