11[#1410-html-entity-parser]
2- = 1410. HTML Entity Parser
2+ = 1410. HTML 实体解析器
33
4- { leetcode} /problems/html-entity-parser/[LeetCode - 1410. HTML Entity Parser ^]
4+ https:// leetcode.cn /problems/html-entity-parser/[LeetCode - 1410. HTML 实体解析器 ^]
55
6- * HTML entity parser* is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.
6+ 「 HTML 实体解析器」 是一种特殊的解析器,它将 HTML 代码作为输入,并用字符本身替换掉所有这些特殊的字符实体。
77
8- The special characters and their entities for HTML are:
8+ HTML 里这些特殊字符和它们对应的字符实体包括:
99
10+ * **双引号:** 字符实体为 `"` ,对应的字符是 `"` 。
11+ * **单引号:** 字符实体为 `'` ,对应的字符是 `'` 。
12+ * **与符号:** 字符实体为 `&` ,对应对的字符是 `&` 。
13+ * **大于号:** 字符实体为 `>` ,对应的字符是 `>` 。
14+ * **小于号:** 字符实体为 `<` ,对应的字符是 `<` 。
15+ * **斜线号:** 字符实体为 `⁄` ,对应的字符是 `/` 。
1016
11- * *Quotation Mark:* the entity is `&quot;` and symbol character is `"` .
12- * *Single Quote Mark:* the entity is `&apos;` and symbol character is `'` .
13- * *Ampersand:* the entity is `&amp;` and symbol character is `&` .
14- * *Greater Than Sign:* the entity is `&gt;` and symbol character is `>` .
15- * *Less Than Sign:* the entity is `&lt;` and symbol character is `<` .
16- * *Slash:* the entity is `&frasl;` and symbol character is `/` .
17+ 给你输入字符串 `text` ,请你实现一个 HTML 实体解析器,返回解析器解析后的结果。
1718
19+ *示例 1:*
1820
19- Given the input `text` string to the HTML parser, you have to implement the entity parser.
21+ ....
22+ 输入:text = "& is an HTML entity but &ambassador; is not."
23+ 输出:"& is an HTML entity but &ambassador; is not."
24+ 解释:解析器把字符实体 & 用 & 替换
25+ ....
2026
21- Return _the text after replacing the entities by the special characters_ .
27+ *示例 2:*
2228
23-
24- *Example 1:*
29+ ....
30+ 输入:text = "and I quote: "...""
31+ 输出:"and I quote: \"...\""
32+ ....
2533
26- [subs="verbatim,quotes"]
27- ----
28- *Input:* text = "&amp; is an HTML entity but &ambassador; is not."
29- *Output:* "& is an HTML entity but &ambassador; is not."
30- *Explanation:* The parser will replace the &amp; entity by &
31- ----
34+ *示例 3:*
3235
33- *Example 2:*
36+ ....
37+ 输入:text = "Stay home! Practice on Leetcode :)"
38+ 输出:"Stay home! Practice on Leetcode :)"
39+ ....
3440
35- [subs="verbatim,quotes"]
36- ----
37- *Input:* text = "and I quote: &quot;...&quot;"
38- *Output:* "and I quote: \"...\""
39- ----
41+ *示例 4:*
42+
43+ ....
44+ 输入:text = "x > y && x < y is always false"
45+ 输出:"x > y && x < y is always false"
46+ ....
4047
41-
42- *Constraints:*
48+ *示例 5:*
4349
50+ ....
51+ 输入:text = "leetcode.com⁄problemset⁄all"
52+ 输出:"leetcode.com/problemset/all"
53+ ....
4454
45- * `1 <= text.length <= 10^5^`
46- * The string may contain any possible characters out of all the 256 ASCII characters.
4755
56+ *提示:*
4857
58+ * `+1 <= text.length <= 10^5+`
59+ * 字符串可能包含 256 个ASCII 字符中的任意字符。
4960
5061
5162== 思路分析
5263
64+ 将实体存入 `Map`,然后逐个字符读取,遇到开头 `&` 和结尾 `;` 就专门处理一下。
5365
5466[[src-1410]]
5567[tabs]
@@ -76,4 +88,5 @@ include::{sourcedir}/_1410_HtmlEntityParser.java[tag=answer]
7688
7789== 参考资料
7890
79-
91+ . https://leetcode.cn/problems/html-entity-parser/solutions/2477551/html-shi-ti-jie-xi-qi-by-leetcode-soluti-y851/[1410. HTML 实体解析器 - 官方题解^] -- 在字符串中查找实体,这样处理更简单!
92+ . https://leetcode.cn/problems/html-entity-parser/solutions/2538217/gong-shui-san-xie-jing-dian-zi-fu-chuan-rvdh3/[1410. HTML 实体解析器 - 经典字符串处理与哈希表运用^]
0 commit comments