def find_peak_element(nums):
    """
    Find a peak element in given array by binary search

    :param nums: given array
    :type nums: list[int]
    :return: index of peak element
    :rtype: int
    """
    if len(nums) == 0:
        return -1
    left = 0
    right = len(nums) - 1
    while left + 1 < right:
        mid = (left + right) // 2
        # search on larger side
        if nums[mid - 1] > nums[mid]:
            right = mid - 1
        elif nums[mid + 1] > nums[mid]:
            left = mid + 1
        else:
            return mid
    if left < len(nums) and nums[left] > nums[right]:
        return left
    else:
        return right