Clean python code


  • 0

    Same as I, just ignore the equal items in the tail of nums with num[0].

    Average time complexity is O(logn) while the worst is O(n).

    class Solution(object):
        def search(self, nums, target):
            low, high = 0, len(nums) - 1
            while low < high and nums[low] == nums[high]:
                high -= 1
    
            while low <= high:
                mid = low + high >> 1
                if nums[mid] == target:
                    return True
    
                if (target >= nums[0] and nums[0] <= nums[mid] < target or
                        target < nums[0] and not target < nums[mid] < nums[0]):
                    low = mid + 1
                else:
                    high = mid - 1
            return False

  • 0
    X

    baddest.... you mean worst?


  • 0

    @xinxi531 Yeah, poor english :(


  • 0
    X

    @shiyanhui but a good solution :)


Log in to reply
 

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