C++ state machine, easy understand,  O(n)
The solution is very easy to understand and explain, but just boring\uD83D\uDE05\n\nc++\nclass Solution {\npublic:\n    uint8_t state = 0;\n    string buf;\n   
The solution is very easy to understand and explain, but just boring\uD83D\uDE05\n\n```c++\nclass Solution {\npublic:\n    uint8_t state = 0;\n    string buf;\n    string res;\n    char cur;\n    \n    unordered_map<string, char> m{\n        {"&quot;", \'"\'},\n        {"&apos;", \'\\\'\'},\n        {"&amp;", \'&\'},\n        {"&gt;", \'>\'},\n        {"&lt;", \'<\'},\n        {"&frasl;", \'/\'}\n    };\n    \n    string entityParser(string text) {\n        for (auto ch : text) {\n            cur = ch;\n            buf.push_back(ch);\n            switch (state) {\n                case 0:\n                    if (ch != \'&\') {\n                        res.push_back(ch);\n                        buf.pop_back();\n                    } else {\n                        state = 1;\n                    }\n                    break;\n                case 1:\n                    switch (ch) {\n                        case \'q\':\n                            state = 2;\n                            break;\n                        case \'a\':\n                            state = 3;\n                            break;\n                        case \'g\':\n                            state = 4;\n                            break;\n                        case \'l\':\n                            state = 5;\n                            break;\n                        case \'f\':\n                            state = 6;\n                            break;\n                        default:\n                            reset();\n                            break;\n                    }\n                    break;\n                case 2:\n                    transition(\'u\', 7);\n                    break;\n                case 3:\n                    if (ch == \'p\') {\n                        state = 8;\n                    } else if (ch == \'m\') {\n                        state = 9;\n                    } else {\n                        reset();\n                    }\n                    break;\n                case 4:\n                    transition(\'t\', 15);\n                    break;\n                case 5:\n                    transition(\'t\', 15);\n                    break;\n                case 6:\n                    transition(\'r\', 10);\n                    break;\n                case 7:\n                    transition(\'o\', 11);\n                    break;\n                case 8:\n                    transition(\'o\', 12);\n                    break;\n                case 9:\n                    transition(\'p\', 15);\n                    break;\n                case 10:\n                    transition(\'a\', 13);\n                    break;\n                case 11:\n                    transition(\'t\', 15);\n                    break;\n                case 12:\n                    transition(\'s\', 15);\n                    break;\n                case 13:\n                    transition(\'s\', 14);\n                    break;\n                case 14:\n                    transition(\'l\', 15);\n                    break;\n                case 15:\n                    unescaped();\n                    break;\n            };\n        }\n        \n        return res;\n    }\n    \n    void reset() {\n        state = 0;\n        res.append(buf);\n        buf.clear();\n    }\n    \n    void transition(char target, uint8_t to) {\n        if (cur == target) {\n            state = to;\n        } else {\n            reset();\n        }\n    }\n    \n    void unescaped() {\n        if (cur == \';\') {\n            state = 0;\n            res.push_back(m[buf]);\n            buf.clear();\n        } else {\n            reset();\n        }\n    }\n};\n```
['C']