3503. Longest Palindrome After Substring Concatenation I Medium
1/**
2 * [3503] Longest Palindrome After Substring Concatenation I
3 *
4 * You are given two strings, s and t.
5 * You can create a new string by selecting a <span data-keyword="substring">substring</span> from s (possibly empty) and a substring from t (possibly empty), then concatenating them in order.
6 * Return the length of the longest <span data-keyword="palindrome-string">palindrome</span> that can be formed this way.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "a", t = "a"</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * Concatenating "a" from s and "a" from t results in "aa", which is a palindrome of length 2.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">s = "abc", t = "def"</span>
18 * Output: <span class="example-io">1</span>
19 * Explanation:
20 * Since all characters are different, the longest palindrome is any single character, so the answer is 1.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">s = "b", t = "aaaa"</span>
25 * Output: 4
26 * Explanation:
27 * Selecting "aaaa" from t is the longest palindrome, so the answer is 4.
28 * </div>
29 * <strong class="example">Example 4:
30 * <div class="example-block">
31 * Input: <span class="example-io">s = "abcde", t = "ecdba"</span>
32 * Output: 5
33 * Explanation:
34 * Concatenating "abc" from s and "ba" from t results in "abcba", which is a palindrome of length 5.
35 * </div>
36 *
37 * Constraints:
38 *
39 * 1 <= s.length, t.length <= 30
40 * s and t consist of lowercase English letters.
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/longest-palindrome-after-substring-concatenation-i/
46// discuss: https://leetcode.com/problems/longest-palindrome-after-substring-concatenation-i/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn longest_palindrome(s: String, t: String) -> i32 {
52 0
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_3503() {
64 }
65}
66Back
© 2026 bowen.ge All Rights Reserved.