Write a method encode that takes a single
String argument and returns its run-length encoding: each run
of consecutive identical characters becomes the character followed by the
length of the run. For example, encode("aaabcc") should
return "a3b1c2". Note that a run can be more than ten
characters long: encode("aaaaaaaaaaaa") should return
"a12". And the encoding of the empty string is the empty
string. (You can assume there are no digit characters in the string to be
encoded. Why is this important?)
Write a method decode that takes an encoded
String and returns the original string:
decode("a3b1c2") should return "aabcc".
Remember that a run count can be more than one digit long:
decode("a12") is twelve as, not one
a followed by something starting with 2. You
can assume the input is a valid encoding produced by
encode.
Run-length encoding is a simple form of data compression: instead of storing every character of a string, we store each run of repeated characters as the character followed by the number of times it repeats in a row. You will write both halves: a method that encodes a string and a method that decodes an encoded string back to the original.