Class Solution
java.lang.Object
g1601_1700.s1616_split_two_strings_to_make_palindrome.Solution
1616 - Split Two Strings to Make Palindrome.<p>Medium</p>
<p>You are given two strings <code>a</code> and <code>b</code> of the same length. Choose an index and split both strings <strong>at the same index</strong> , splitting <code>a</code> into two strings: <code>a<sub>prefix</sub></code> and <code>a<sub>suffix</sub></code> where <code>a = a<sub>prefix</sub> + a<sub>suffix</sub></code>, and splitting <code>b</code> into two strings: <code>b<sub>prefix</sub></code> and <code>b<sub>suffix</sub></code> where <code>b = b<sub>prefix</sub> + b<sub>suffix</sub></code>. Check if <code>a<sub>prefix</sub> + b<sub>suffix</sub></code> or <code>b<sub>prefix</sub> + a<sub>suffix</sub></code> forms a palindrome.</p>
<p>When you split a string <code>s</code> into <code>s<sub>prefix</sub></code> and <code>s<sub>suffix</sub></code>, either <code>s<sub>suffix</sub></code> or <code>s<sub>prefix</sub></code> is allowed to be empty. For example, if <code>s = "abc"</code>, then <code>"" + "abc"</code>, <code>"a" + "bc"</code>, <code>"ab" + "c"</code> , and <code>"abc" + ""</code> are valid splits.</p>
<p>Return <code>true</code> <em>if it is possible to form</em> <em>a palindrome string, otherwise return</em> <code>false</code>.</p>
<p><strong>Notice</strong> that <code>x + y</code> denotes the concatenation of strings <code>x</code> and <code>y</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> a = “x”, b = “y”</p>
<p><strong>Output:</strong> true <strong>Explaination:</strong> If either a or b are palindromes the answer is true since you can split in the following way:</p>
<p>a<sub>prefix</sub> = "", a<sub>suffix</sub> = “x”</p>
<p>b<sub>prefix</sub> = "", b<sub>suffix</sub> = “y”</p>
<p>Then, a<sub>prefix</sub> + b<sub>suffix</sub> = "" + “y” = “y”, which is a palindrome.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> a = “xbdef”, b = “xecab”</p>
<p><strong>Output:</strong> false</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> a = “ulacfd”, b = “jizalu”</p>
<p><strong>Output:</strong> true <strong>Explaination:</strong> Split them at index 3:</p>
<p>a<sub>prefix</sub> = “ula”, a<sub>suffix</sub> = “cfd”</p>
<p>b<sub>prefix</sub> = “jiz”, b<sub>suffix</sub> = “alu”</p>
<p>Then, a<sub>prefix</sub> + b<sub>suffix</sub> = “ula” + “alu” = “ulaalu”, which is a palindrome.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= a.length, b.length <= 10<sup>5</sup></code></li>
<li><code>a.length == b.length</code></li>
<li><code>a</code> and <code>b</code> consist of lowercase English letters</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
checkPalindromeFormation
-