human
I am working on the file "02_BinarySearch.ipynb".
The first task is:
Search in Rotated Sorted Array

You are given a target value to search. If found in the array return its index, otherwise return -1.
https://leetcode.com/problems/search-in-rotated-sorted-array/#/description
Can you write Python code for it?
assistant
#Here is the Python code you requested.

# trival way
class Solution(object):
    def search(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        n = len(nums)
        if nums is None or n == 0:
            return -1
        
        # find the minimun index
        start, end = 0, n-1
        while start < end:
            mid = start + (end - start) / 2
            if nums[mid] > nums[end]:
                start = mid + 1
            else:
                end = mid
        mark = start
        
        # binary search
        start, end = 0, n-1
        while start + 1 < end:
            mid = start + (end - start) / 2
            realmid = (mid + mark) % n
            if nums[realmid] == target:
                return realmid    ## important !!
            elif nums[realmid] < target:
                start = mid + 1
            else:
                end = mid - 1
        
        if nums[(start + mark) % n] == target:
            return (start + mark) % n
        if nums[(end + mark) % n] == target:
            return (end + mark) % n 
        return -1        

# good way: beats 96.13%  key of bisection: shirink the interval !!
class Solution(object):
    def search(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        n = len(nums)
        if nums is None or n == 0:
            return -1
        
        # binary search
        start, end = 0, n-1
        while start + 1 < end:
            mid = start + (end - start) / 2
            if nums[mid] == target:
                return mid
            elif nums[mid] > nums[end]:
                if nums[end] < target < nums[mid]:
                    end = mid - 1
                else:
                    start = mid
            else:
                if nums[mid] < target <= nums[end]:
                    start = mid + 1
                else:
                    end = mid
        
        if nums[start] == target:
            return start
        if...