forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1410.py
More file actions
27 lines (26 loc) · 708 Bytes
/
1410.py
File metadata and controls
27 lines (26 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution:
def entityParser(self, text: str) -> str:
res = []
n, i = len(text), 0
entity = {
'"': '\"',
'&apos': "'",
'>': '>',
'<': '<',
'&frasl': '/',
'&': '&',
}
while i < n:
if text[i] == '&':
t = ''
while text[i] != ';':
t += text[i]
i += 1
if t in entity:
res.append(entity[t])
else:
res.append(t + ";")
else:
res.append(text[i])
i += 1
return "".join(res)