测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | FAIL |
| Plus 测试 | FAIL |
| 代码长度 | 1052 字符 |
模型生成的代码 (1052 字符)
def get_Inv_Count(arr):
"""
Count inversions in the given array.
An inversion is a pair (i, j) such that i < j and arr[i] > arr[j].
This implementation uses a merge-sort based approach with O(n log n) time complexity.
"""
def merge_and_count(left, right):
merged = []
count = 0
i = j = 0
while i < len(left) and j < len(right):
if left[i] <= right[j]:
merged.append(left[i])
i += 1
else:
# All remaining elements in left are greater than right[j]
merged.append(right[j])
count += len(left) - i
j += 1
# Append remaining elements
merged.extend(left[i:])
merged.extend(right[j:])
return merged, count
def sort_and_count(arr):
if len(arr) <= 1:
return arr, 0
mid = len(arr) // 2
left, left_count = sort_and_count(arr[:mid])
right, right_count = sort_and_count(arr[mid:])
merged, merge_count
Base 失败测试用例
[[1, 20, 6, 4, 5]]
Plus 失败测试用例
[[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]