Mbpp/119

⚠️ 仅 Base 通过 Base: PASS Plus: FAIL
测试评估
指标结果
Base 测试PASS
Plus 测试FAIL
代码长度879 字符
模型生成的代码 (879 字符)
def search(arr):
    """
    Returns the element that appears exactly once in a sorted array 
    where every other element appears exactly twice.
    The array is sorted and has odd length.
    """
    left, right = 0, len(arr) - 1
    while left < right:
        mid = left + (right - left) // 2
        if mid % 2 == 0:  # mid is even index
            if arr[mid] == arr[mid + 1]:
                # pairs are valid from left to mid+1, single is on the right
                left = mid + 2
            else:
                # single is on the left (including mid)
                right = mid
        else:  # mid is odd index
            if arr[mid] == arr[mid - 1]:
                # pairs are valid up to mid, single is on the right
                left = mid + 1
            else:
                # single is on the left
                right = mid - 1
    return arr[left]
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • [[]]