Class Solution
-
- All Implemented Interfaces:
public final class Solution3503 - Longest Palindrome After Substring Concatenation I.
Medium
You are given two strings,
sandt.You can create a new string by selecting a substring from
s(possibly empty) and a substring fromt(possibly empty), then concatenating them in order.Return the length of the longest palindrome that can be formed this way.
Example 1:
Input: s = "a", t = "a"
Output: 2
Explanation:
Concatenating
"a"fromsand"a"fromtresults in"aa", which is a palindrome of length 2.Example 2:
Input: s = "abc", t = "def"
Output: 1
Explanation:
Since all characters are different, the longest palindrome is any single character, so the answer is 1.
Example 3:
Input: s = "b", t = "aaaa"
Output: 4
Explanation:
Selecting "
aaaa" fromtis the longest palindrome, so the answer is 4.Example 4:
Input: s = "abcde", t = "ecdba"
Output: 5
Explanation:
Concatenating
"abc"fromsand"ba"fromtresults in"abcba", which is a palindrome of length 5.Constraints:
1 <= s.length, t.length <= 30sandtconsist of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerlongestPalindrome(String s, String t)-
-
Method Detail
-
longestPalindrome
final Integer longestPalindrome(String s, String t)
-
-
-
-