Two more lines based on Search in Rotated


  • 0
    A
    class Solution(object):
        def search(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: bool
            """
            low = 0
            high = len(nums) - 1
            while low <= high:
                mid = (low+high) / 2
                if nums[mid] == target:
                    return True
                else:
                    if nums[mid] < nums[high]:
                        if nums[mid] < target and target <= nums[high]:
                            low = mid + 1
                        else:
                            high = mid - 1
                    elif nums[mid] > nums[high]:
                        if nums[mid] > target and target >= nums[low]:
                            high = mid - 1
                        else:
                            low = mid + 1
                    else:
                        high -= 1
    
            return False
    

Log in to reply
 

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