Java solution (20 ms) beats 100% time & space
\nclass Solution {\n    public static Map<String, String> map;\n\n    static {\n        map = new HashMap<>();\n        map.put("&quot;", "\\"");\n        map.p
```\nclass Solution {\n    public static Map<String, String> map;\n\n    static {\n        map = new HashMap<>();\n        map.put("&quot;", "\\"");\n        map.put("&apos;", "\'");\n        map.put("&amp;", "&");\n        map.put("&gt;", ">");\n        map.put("&lt;", "<");\n        map.put("&frasl;", "/");\n    }\n\n    public String entityParser(String text) {\n        StringBuilder sb = new StringBuilder();\n        char[] arr = text.toCharArray();\n        for (int i = 0; i < arr.length; i++) {\n            boolean special = false;\n            if (arr[i] == \'&\') { // start with &\n                for (String s : map.keySet()) {\n                    if (isSpecial(arr, i, s)) {  // if it is special string\n                        sb.append(map.get(s));\n                        i += s.length() - 1;\n                        special = true;\n                        break;\n                    }\n                }\n            }\n            if (!special) sb.append(arr[i]);\n        }\n        return sb.toString();\n    }\n\n    private boolean isSpecial(char[] arr, int i, String s) {\n        for (char c : s.toCharArray()) {\n            if (arr[i++] != c) return false;\n        }\n        return true;\n    }\n}\n// Runtime: 28 ms\n```\n\nWe can improve performance a little bit by using Array instead of HashMap.\n\n```\nclass Solution {\n    String[] key = {"&quot;", "&apos;", "&amp;", "&gt;", "&lt;", "&frasl;"};\n    String[] value = {"\\"", "\'", "&", ">", "<", "/"};\n    \n    public String entityParser(String text) {\n        StringBuilder sb = new StringBuilder();\n        char[] arr = text.toCharArray();\n        for (int i = 0; i < arr.length; i++) {\n            boolean special = false;\n            if (arr[i] == \'&\') { // start with &\n                for (int j = 0; j< 6; j++) {\n                    if (isSpecial(arr, i, key[j])) {  // if it is special string\n                        sb.append(value[j]);\n                        i += key[j].length() - 1;\n                        special = true;\n                        break;\n                    }\n                }\n            }\n            if (!special) sb.append(arr[i]);\n        }\n        return sb.toString();\n    }\n\n    private boolean isSpecial(char[] arr, int i, String s) {\n        for (char c : s.toCharArray()) {\n            if (arr[i++] != c) return false;\n        }\n        return true;\n    }\n}\n// Run time: 20 ms\n```
[]