Mbpp/11

✅ 完美通过 Base: PASS Plus: PASS
测试评估
指标结果
Base 测试PASS
Plus 测试PASS
代码长度535 字符
模型生成的代码 (535 字符)
def remove_Occ(s: str, ch: str) -> str:
    """
    Remove the first and last occurrence of a given character from the string.
    If the character appears only once, that single occurrence is removed.
    If the character is not present, the original string is returned.
    """
    first = s.find(ch)
    if first == -1:  # character not found
        return s
    last = s.rfind(ch)
    if first == last:  # only one occurrence
        return s[:first] + s[first+1:]
    else:
        return s[:first] + s[first+1:last] + s[last+1:]
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • 无失败测试