public class Codec {
// Encodes a list of strings to a single string.
public String encode(List<String> strs) {
StringBuilder sb = new StringBuilder();
for (String str : strs) {
sb.append(str.length()).append('#').append(str);
}
return sb.toString();
}
// Decodes a single string to a list of strings.
public List<String> decode(String s) {
List<String> res = new ArrayList<String>();
int len = s.length();
int i = 0;
while (i < len) {
int val = 0;
while (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
val = val * 10 + s.charAt(i++) - '0';
}
res.add(s.substring(++i, i + val));
i += val;
}
return res;
}
}
// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.decode(codec.encode(strs));