Skip to content

Missing Test Case - 1616. Split Two Strings to Make Palindrome #30449

@ggb-ljh

Description

@ggb-ljh

LeetCode 用户名

GGB

问题号码、标题和链接

  1. 分割两个字符串得到回文串 https://leetcode.cn/problems/split-two-strings-to-make-palindrome/

Bug Category

缺少测试用例 (由于缺少测试用例而接受不正确/低效的代码)

描述

当输入
a = "xx"
b = "yy"
时,我的代码由于没有正确处理字符串切片的索引为-1时的情况,导致输出False

你使用的语言

Python/Python3

你提交或者运行的代码

class Solution:
    def check(self, a, b):
        i, j = 0, len(a) - 1
        while i < j:
            if a[i] == b[j]:
                i += 1
                j -= 1
            else:
                return (
                    a[i : j + 1] == a[j : i - 1 : -1]
                    or b[i : j + 1] == b[j : i - 1 : -1]
                )
        return True

    def checkPalindromeFormation(self, a: str, b: str) -> bool:
        return self.check(a, b) or self.check(b, a)

期望行为

当输入
a = "xx"
b = "yy"
时,应输出True

屏幕截图

No response

额外的上下文

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions