<jupyter_start><jupyter_text>说明：    您会得到两个长度相同的字符串a和b。    选择一个索引并将两个字符串拆分为相同的索引，    将a拆分为两个字符串：aprefix和asuffix，其中a = aprefix + asuffix，    将b拆分为两个字符串：bprefix和bsuffix，其中b = bprefix + bsuffix。    检查aprefix + bsuffix或 bprefix + asuffix是否形成回文。    将字符串s拆分为sprefix和ssuffix时，ssuffix或sprefix都可以为空。    例如，如果s =“abc”，则 “” + “abc”，“a” + “ bc”，“ab” +  c”和“abc” “” 是有效的分割。    如果可以形成回文字符串，则返回true，否则返回false。    注意，x y表示字符串x和y的串联。Example 1:    Input: a = "x", b = "y"    Output: true    Explaination:   If either a or b are palindromes the answer is true since you can split in the following way:                    aprefix = "", asuffix = "x"                    bprefix = "", bsuffix = "y"                    Then, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.Example 2:    Input: a = "abdef", b = "fecab"    Output: trueExample 3:    Input: a = "ulac fd", b = "jiza lu"    Output: true    Explaination: Split them at index 3:                  aprefix = "ula", asuffix = "cfd"                  bprefix = "jiz", bsuffix = "alu"                  Then, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.Example 4:    Input: a = "xbdef", b = "xecab"    Output: falseConstraints:    1、1 <= a.length, b.length <= 10^5    2、a.length == b.length    3、a and b consist of lowercase English letters<jupyter_code>class Solution:
    def checkPalindromeFormation(self, a: str, b: str) -> bool:
        if a[::-1] == a or b[::-1] == b: return True
        N = len(a)
        valid = 1 if N % 2 == 0 else 2
        # a_pre + b_suf = N or a_pre + b_suf + 1 = N: True
        if a[0] == b[-1]:
            a_idx, b_idx = 0, N - 1
            while a_idx < N:
                if a[a_idx] == b[b_idx]:
                    print(a_idx, b_idx)
                    if b_idx - a_idx == valid:
                        return True
                    a_idx += 1
                    b_idx -= 1
                else:
                    break
        elif a[-1] == b[0]:
            a_idx, b_idx = N - 1, 0
            while b_idx < N:
                if a[a_idx] == b[b_idx]:
                    if a_idx - b_idx == valid:
                        return True
                    a_idx -= 1
                    b_idx += 1
                else:
                    break
        return False
class Solution:
    def checkPalindromeFormation(self, a: str, b: str) -> bool:
        return self.inner(a,b) or self.inner(b, a)
    
    def inner(self, a, b):
        l, r = 0, len(a) - 1
        ab, aa, bb = True, True, True
        while l < r and (ab or aa or bb):
            aa = (ab or aa) and a[l] == a[r]
            bb = (ab or bb) and b[l] == b[r]
            ab = ab and a[l] == b[r]
            l, r = l + 1, r - 1
        return aa or ab or bb
class Solution:
    def checkPalindromeFormation(self, a: str, b: str) -> bool:
        n = len(a)
        i = 0
        while i <= n // 2 and a[i] == b[n - 1 - i]:
            i += 1
        j = 0
        while j <= n // 2 and b[j] == a[n - 1 - j]:
            j += 1
        val = max(i, j)
        return self.helper(a, val, n) or self.helper(b, val, n)
    
    def helper(self, a, val, n):
        left = val
        right = n - val - 1
        while right - left >= 1 and a[left] == a[right]:
            left += 1
            right -= 1
        if right - left < 1:
            return True
solution = Solution()
solution.checkPalindromeFormation(a = "<KEY>", b = "<KEY>")
a = "pvhm upgqeltozftlmfjjde", 
b = "<KEY>"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13022323983972525, 'fraction_numerical': 0.013737836290784202, 'mean_word_length': 1.5399709302325582, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '200400', 'license': 'Apache-2.0', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1316, 'n_words': 377, 'path': 'String/1012/1616. Split Two Strings to Make Palindrome.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '3546'}