HTML Entity Parser LeetCode solution in C++
1class Solution {2public:3string entityParser(string text) {4map<string, char> mp;5mp["""] = '\"';6mp["'"] = '\'';7mp["&"] = '&';8mp[">"] = '>';9mp["<"] = '<';10mp["⁄"] = '/';1112for (int i = 0; i < text.size(); i++) {13if (text[i] == '&') {14int j = i;15string com = "";16while (text[j] != ';' && j < text.size()) {17com += text[j];18j++;19}20com += text[j];21if (mp.find(com) != mp.end()) {22text.erase(i, j - i);23text[i] = mp[com];24}25}26}27return text;28}29};