测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | PASS |
| Plus 测试 | PASS |
| 代码长度 | 578 字符 |
模型生成的代码 (578 字符)
def find_first_occurrence(arr, target):
"""
Returns the index of the first occurrence of target in a sorted array.
If target is not present, returns -1.
Uses binary search for O(log n) time complexity.
"""
left, right = 0, len(arr)
while left < right:
mid = (left + right) // 2
if arr[mid] < target:
left = mid + 1
else:
right = mid
# At this point, left is the index of the first element >= target
if left < len(arr) and arr[left] == target:
return left
return -1
Base 失败测试用例
- 无失败测试
Plus 失败测试用例
- 无失败测试