<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>html Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/html/</link>
	<description></description>
	<lastBuildDate>Sun, 12 Apr 2020 06:35:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>html Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/html/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1410. HTML Entity Parser</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-1410-html-entity-parser/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-1410-html-entity-parser/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 12 Apr 2020 06:35:21 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6600</guid>

					<description><![CDATA[<p>HTML entity parser&#160;is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself. The&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1410-html-entity-parser/">花花酱 LeetCode 1410. HTML Entity Parser</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><strong>HTML entity parser</strong>&nbsp;is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself.</p>



<p>The special characters and their entities for HTML are:</p>



<ul><li><strong>Quotation Mark:</strong>&nbsp;the entity is&nbsp;<code>&amp;quot;</code>&nbsp;and&nbsp;symbol character is&nbsp;<code>"</code>.</li><li><strong>Single Quote&nbsp;Mark:</strong>&nbsp;the entity is&nbsp;<code>&amp;apos;</code>&nbsp;and&nbsp;symbol character is&nbsp;<code>'</code>.</li><li><strong>Ampersand:</strong>&nbsp;the entity is&nbsp;<code>&amp;amp;</code>&nbsp;and symbol character is&nbsp;<code>&amp;</code>.</li><li><strong>Greater Than Sign:</strong>&nbsp;the entity is&nbsp;<code>&amp;gt;</code>&nbsp;and symbol character is&nbsp;<code>&gt;</code>.</li><li><strong>Less Than Sign:</strong>&nbsp;the entity is&nbsp;<code>&amp;lt;</code>&nbsp;and symbol character is&nbsp;<code>&lt;</code>.</li><li><strong>Slash:</strong>&nbsp;the entity is&nbsp;<code>&amp;frasl;</code>&nbsp;and&nbsp;symbol character is&nbsp;<code>/</code>.</li></ul>



<p>Given the input&nbsp;<code>text</code>&nbsp;string to the HTML parser, you have to implement the entity parser.</p>



<p>Return&nbsp;<em>the text</em>&nbsp;after replacing the entities by the special characters.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> text = "&amp;amp; is an HTML entity but &amp;ambassador; is not."
<strong>Output:</strong> "&amp; is an HTML entity but &amp;ambassador; is not."
<strong>Explanation:</strong> The parser will replace the &amp;amp; entity by &amp;
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> text = "and I quote: &amp;quot;...&amp;quot;"
<strong>Output:</strong> "and I quote: \"...\""
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> text = "Stay home! Practice on Leetcode :)"
<strong>Output:</strong> "Stay home! Practice on Leetcode :)"
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> text = "x &amp;gt; y &amp;amp;&amp;amp; x &amp;lt; y is always false"
<strong>Output:</strong> "x &gt; y &amp;&amp; x &lt; y is always false"
</pre>



<p><strong>Example 5:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> text = "leetcode.com&amp;frasl;problemset&amp;frasl;all"
<strong>Output:</strong> "leetcode.com/problemset/all"
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= text.length &lt;= 10^5</code></li><li>The string may contain any possible characters out of all the 256&nbsp;ASCII characters.</li></ul>



<h2><strong>Solution: Simulation</strong></h2>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string entityParser(string text) {    
    map&lt;string, string&gt; m{
      {&quot;&amp;quot;&quot;, &quot;\&quot;&quot;}, {&quot;&amp;apos;&quot;, &quot;'&quot;}, {&quot;&amp;amp;&quot;, &quot;&amp;&quot;}, 
      {&quot;&amp;gt;&quot;, &quot;&gt;&quot;}, {&quot;&amp;lt;&quot;, &quot;&lt;&quot;}, {&quot;&amp;frasl;&quot;, &quot;/&quot;}};
    string ans;
    string buf;
    for (char c : text) {
      buf += c;
      if (buf.back() != ';') continue;
      const int l = buf.size();
      for (const auto&amp; [k, v] : m) {
        const int kl = k.length();
        if (l &gt;= kl &amp;&amp; buf.substr(l - kl) == k) {
          ans += buf.substr(0, l - kl) + v;
          buf.clear();
          break;
        }            
      }      
    }    
    return ans + buf;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1410-html-entity-parser/">花花酱 LeetCode 1410. HTML Entity Parser</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/simulation/leetcode-1410-html-entity-parser/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
