Question: CreateaclassRunLengthEncodethatcontainsthemethod encode which takes one argument: a String to be encoded as described below. The return value should bea String which has been encoded with
CreateaclassRunLengthEncodethatcontainsthemethod encode which takes one argument: a String to be encoded as described below.
The return value should bea String which has been encoded with the following algorithm:
If any character is repeated more than 4 times, the entire set of repeated characters should be replaced with a slash '/', followed by a 2-digit number which is the length of the set of characters, and the character. For example, "aaaaa" would be encoded as "/05a". Runs of 4 or less characters should not be replaced since performing the encoding would not decrease the length of the string.
Notes
Letters are case-sensitive. For example "AaAaAa" cannot be encoded.
You may only encode repeats of a single character, repeats of multiple characters cannot be encoded. For example "ababababab" cannot be encoded as "/05ab".
Please do this in java
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
