测试评估
| 指标 | 结果 |
|---|---|
| Base 测试 | FAIL |
| Plus 测试 | FAIL |
| 代码长度 | 675 字符 |
模型生成的代码 (675 字符)
def remove_Occ(s: str, ch: str) -> str:
"""
Remove the first and last occurrence of the given character from the string.
If the character appears only once, that single occurrence is removed.
If the character does not appear, the original string is returned.
"""
first = s.find(ch)
last = s.rfind(ch)
# character not found
if first == -1:
return s
# If there is only one occurrence (first == last), remove it once
if first == last:
return s[:first] + s[first+1:]
# Remove the last occurrence first to keep the first index valid,
# then remove the first occurrence.
# Remove last
s = s
Base 失败测试用例
['hello', 'l']
Plus 失败测试用例
['aaa', 'a']