Python 3*(N-1) times calling of knows()


  • 0

    Can you do better than 3*(N-1)?

    class Solution(object):
        def findCelebrity(self, n):
            left, right = 0, n - 1
            while left != right:
                if knows(left, right):
                    left += 1
                else:
                    right -= 1
            for i in xrange(n):
                if i != left:
                    if not knows(i, left) or knows(left, i):
                        return -1
            return left
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.