Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
39 lines (29 loc) · 968 Bytes

File metadata and controls

39 lines (29 loc) · 968 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.ArrayList;
import java.util.List;
public class Codec {
String SPLIT = ":";
// Encodes a list of strings to a single string.
public String encode(List<String> strs) {
StringBuilder encoded = new StringBuilder();
for(String str : strs) {
encoded.append(str.length()).append(SPLIT).append(str);
}
return encoded.toString();
}
// Decodes a single string to a list of strings.
public List<String> decode(String s) {
List<String> decoded = new ArrayList<>();
int pointer = 0;
while(pointer < s.length()) {
int index = s.indexOf(SPLIT, pointer);
int length = Integer.parseInt(s.substring(pointer, index));
String str = s.substring(index + 1, index + 1 + length);
decoded.add(str);
pointer = index + 1 + length;
}
return decoded;
}
}
// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.decode(codec.encode(strs));
Morty Proxy This is a proxified and sanitized view of the page, visit original site.