Problem Statement
????
You are given a String input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case of a tie, return the string that occurs earliest in input.
Definition
????
Class:
ReverseSubstring
Method:
findReversed
Parameters:
String
Returns:
String
Method signature:
String findReversed(String input)
(be sure your method is public)
????
Notes
-
The substring and its reversal may overlap partially or completely.
-
The entire original string is itself a valid substring (see example 4).
Constraints
-
input will contain between 1 and 50 characters, inclusive.
-
Each character of input will be an uppercase letter ('A'-'Z').
Examples
0)
????
"XBCDEFYWFEDCBZ"
Returns: "BCDEF"
We see that the reverse of BCDEF is FEDCB, which appears later in the string.
1)
????
"XYZ"
Returns: "X"
The best we can do is find a one character substring, so we implement the tie-breaker rule of taking the earliest one first.
2)
????
"ABCABA"
Returns: "ABA"
The string ABA is a palindrome (it's its own reversal), so it meets the criteria.
3)
????
"FDASJKUREKJFDFASIREYUFDHSAJYIREWQ"
Returns: "FDF"
4)
????
"ABCDCBA"
Returns: "ABCDCBA"
Here, the entire string is its own reversal.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
博客围绕寻找字符串中最长反转子串的问题展开。给定一个字符串,需找出其最长子串,且该子串的反转也是原字符串的子串,若有多个符合条件的子串,取最早出现的。同时给出了输入字符串的约束条件和多个示例。
2万+

被折叠的 条评论
为什么被折叠?



