测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | PASS |
| Plus 测试 | PASS |
| 代码长度 | 1467 字符 |
模型生成的代码 (1467 字符)
def next_smallest_palindrome(n: int) -> int:
"""
Returns the smallest palindrome integer strictly greater than n.
"""
if n < 0:
# Assuming non-negative integers; if negative, treat as -1 and next palindrome is 0?
# According to typical problem, we expect non-negative. We'll return 0 for negative.
return 0
s = str(n)
length = len(s)
# Special case: all digits are 9
if all(ch == '9' for ch in s):
return n + 2 # 9 -> 11, 99 -> 101, 999 -> 1001
# Convert to list of digits for manipulation
digits = list(s)
# Mirror left half to right half
def mirror(left_half):
mirrored = left_half + left_half[-1 - (length % 2)::-1]
return int(''.join(mirrored))
left_half = digits[:(length + 1) // 2]
candidate = mirror(left_half)
if candidate > n:
return candidate
# Otherwise increment the middle and propagate carry if needed
left_half_int = int(''.join(left_half))
left_half_int += 1
left_half = list(str(left_half_int))
# If the left half length increased due to carry (e.g., 199 -> 200), adjust
# This happens when left_half was 19 and becomes 20, length unchanged, but mirror still works.
# However, if original left half length increases, that means the number of digits might
# change, but we've already handled all 9's case, so it won't increase in length.
return mirror(left_half)
Base 失败测试用例
- 无失败测试
Plus 失败测试用例
- 无失败测试