Problem Statement
You are given a String s. Return the shortest string which contains s as a contiguous substring twice.
Note that two occurrences of s may overlap. For example, "ababa" contains "aba" twice.
Definition
- Class:
- TwiceString
- Method:
- getShortest
- Parameters:
- String
- Returns:
- String
- Method signature:
- String getShortest(String s)
- (be sure your method is public)
Notes
- The shortest string which contains s as a contiguous substring twice is always unique.
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character in s will be a lowercase letter ('a'-'z').
Examples
"aba"
Returns: "ababa"
This is the example shown in the problem statement."xxxxx"
Returns: "xxxxxx"
"topcoder"
Returns: "topcodertopcoder"
"abracadabra"
Returns: "abracadabracadabra"