Mbpp/733

✅ 完美通过 Base: PASS Plus: PASS
测试评估
指标结果
Base 测试PASS
Plus 测试PASS
代码长度585 字符
模型生成的代码 (585 字符)
def find_first_occurrence(arr, target):
    """
    Returns the index of the first occurrence of target in a sorted array arr.
    If target is not found, returns -1.
    Uses binary search for O(log n) time complexity.
    """
    left, right = 0, len(arr) - 1
    result = -1
    while left <= right:
        mid = left + (right - left) // 2
        if arr[mid] == target:
            result = mid
            right = mid - 1  # continue searching on the left side
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return result
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • 无失败测试