Mbpp/793

✅ 完美通过 Base: PASS Plus: PASS
测试评估
指标结果
Base 测试PASS
Plus 测试PASS
代码长度592 字符
模型生成的代码 (592 字符)
def last(arr, target):
    """
    Find the last occurrence index of target in a sorted array using binary search.
    Returns -1 if target is not found.
    """
    left, right = 0, len(arr) - 1
    result = -1

    while left <= right:
        mid = left + (right - left) // 2
        if arr[mid] == target:
            result = mid          # found one occurrence, but check right for later one
            left = mid + 1        # move right to find the last occurrence
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1

    return result
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • 无失败测试