binary search in python


  • 0
    F
        def singleNonDuplicate(self, nums):
            start, end = 0, len(nums) - 1
            while start < end:
                mid = (start + end) / 2
                if mid % 2:
                    mid -= 1
                if nums[mid] == nums[mid + 1]:
                    start += 2
                else:
                    end = mid
            return nums[start]

Log in to reply
 

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