Problem Statement |
| Given a string s of length n, one can generate an infinite cyclical sequence a0, a1, ...
as follows. For each non-negative integer i, compute a zero-based index j as j = i%n. ai is equal to the j-th character of s.
You are given a String s. Return the shortest string which generates the same sequence as s. |
|
Definition |
| Class: | CyclicSequence | Method: | minimalCycle | Parameters: | String | Returns: | String | Method signature: | String minimalCycle(String s) | (be sure your method is public) |
|
|
|
|
Constraints |
- | s will contain between 1 and 50 characters, inclusive. |
- | Each character in s will be a digit ('0'-'9'). |
|
Examples |
0) | |
| | Returns: "1" | The sequence generated by this string is ai=1, which can be generated by the string "1". |
|
|
1) | |
| |
2) | |
| |
3) | |
| |
4) | |
| |