def search(nums, target):
    """
    Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
    You are given a target value to search. If found in the array return its index, otherwise return -1.
    Your algorithm's runtime complexity must be in the order of O(log n).
    :param nums: list[int]
    :param target: int
    :return: int
    """
    if not nums:
        return -1

    low, high = 0, len(nums) - 1

    while low <= high:
        mid = (low + high) // 2
        if target == nums[mid]:
            return mid

        if nums[low] <= nums[mid]:
            if nums[low] <= target <= nums[mid]:
                high = mid - 1
            else:
                low = mid + 1
        else:
            if nums[mid] <= target <= nums[high]:
                low = mid + 1
            else:
                high = mid - 1

    return -1