Skip to content

Instantly share code, notes, and snippets.

@mgarod
Created November 14, 2016 00:15
Show Gist options
  • Save mgarod/76c0b14ab055fc184754db36efb9948b to your computer and use it in GitHub Desktop.
Save mgarod/76c0b14ab055fc184754db36efb9948b to your computer and use it in GitHub Desktop.
static String Decoding(String[] encodings, String encodedstring) {
HashMap<String, String> map = new HashMap<>(); // <code, char>
for (String s : encodings) {
String[] splited = s.split("\\t");
if (splited[0].equals("[newline]"))
splited[0] = "\n";
map.put(splited[1], splited[0]);
}
String temp = "";
String answer = "";
for (int i = 0; i < encodedstring.length(); ++i) {
char c = encodedstring.charAt(i);
temp += c;
if (map.containsKey(temp)) {
answer += map.get(temp);
temp = "";
}
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment