HTML Entity Parser LeetCode solution in C++

1
class Solution {
2
public:
3
string entityParser(string text) {
4
map<string, char> mp;
5
mp["&quot;"] = '\"';
6
mp["&apos;"] = '\'';
7
mp["&amp;"] = '&';
8
mp["&gt;"] = '>';
9
mp["&lt;"] = '<';
10
mp["&frasl;"] = '/';
11

12
for (int i = 0; i < text.size(); i++) {
13
if (text[i] == '&') {
14
int j = i;
15
string com = "";
16
while (text[j] != ';' && j < text.size()) {
17
com += text[j];
18
j++;
19
}
20
com += text[j];
21
if (mp.find(com) != mp.end()) {
22
text.erase(i, j - i);
23
text[i] = mp[com];
24
}
25
}
26
}
27
return text;
28
}
29
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0