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.

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"
    The similar as above.
4) "ABCDCBA" 
    Returns: "ABCDCBA" 
    Here, the entire string is its own reversal.

Code: Search a Reverse Substringclass ReverseSubstring
}

Results are:
Code: Search a Reverse SubstringBCDEF
Code: Search a Reverse SubstringX
Code: Search a Reverse SubstringABA
Code: Search a Reverse SubstringFDF
Code: Search a Reverse SubstringABCDCBA

相关文章:

  • 2022-01-25
  • 2021-07-26
  • 2021-08-12
  • 2021-06-30
  • 2021-09-25
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2021-12-03
  • 2022-02-12
  • 2021-07-27
  • 2022-12-23
  • 2021-09-15
  • 2022-02-17
  • 2021-11-05
相关资源
相似解决方案