somebody solved this one with reguar expression
Given a string, return its encoding defined as follows:
- First, the string is divided into the least possible number of disjoint substrings consisting of identical characters
- for example,
"aabbbc"
is divided into["aa", "bbb", "c"]
- for example,
- Next, each substring with length greater than one is replaced with a concatenation of its length and the repeating character
- for example, substring
"bbb"
is replaced by"3b"
- for example, substring
- Finally, all the new strings are concatenated together in the same order and a new string is returned.
Example
For
s = "aabbbc"
, the output should belineEncoding(s) = "2a3bc"
.
Input/Output
- [execution time limit] 3 seconds (java)
- [input] string sString consisting of lowercase English letters.Guaranteed constraints:
4 ≤ s.length ≤ 15
. - [output] stringEncoded version of
s
.
[Java] Syntax Tips
// Prints help message to the console
// Returns a string
//
// Globals declared here will cause a compilation error,
// declare variables inside the function instead!
String helloWorld(String name) {
System.out.println("This prints to the console when you Run Tests");
return "Hello, " + name;
}
No comments:
Post a Comment