<?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>email Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/email/</link>
	<description></description>
	<lastBuildDate>Thu, 25 Apr 2019 04:54:06 +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>email Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/email/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 831. Masking Personal Information</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-831-masking-personal-information/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-831-masking-personal-information/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 25 Apr 2019 04:52:06 +0000</pubDate>
				<category><![CDATA[String]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5110</guid>

					<description><![CDATA[<p>We are given a&#160;personal information string&#160;S, which may represent&#160;either&#160;an email address&#160;or&#160;a phone number. We would like to mask this&#160;personal information according to the&#160;following rules: 1.&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-831-masking-personal-information/">花花酱 LeetCode 831. Masking Personal Information</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>We are given a&nbsp;personal information string&nbsp;<code>S</code>, which may represent&nbsp;either&nbsp;<strong>an email address</strong>&nbsp;or&nbsp;<strong>a phone number.</strong></p>



<p>We would like to mask this&nbsp;personal information according to the&nbsp;following rules:</p>



<p><br><strong>1. Email address:</strong></p>



<p>We define a&nbsp;<strong>name</strong>&nbsp;to be a string of&nbsp;<code>length ≥ 2</code>&nbsp;consisting&nbsp;of only lowercase letters&nbsp;<code>a-z</code>&nbsp;or uppercase&nbsp;letters&nbsp;<code>A-Z</code>.</p>



<p>An email address starts with a name, followed by the&nbsp;symbol&nbsp;<code>'@'</code>, followed by a name, followed by the&nbsp;dot&nbsp;<code>'.'</code>&nbsp;and&nbsp;followed by a name.&nbsp;</p>



<p>All email addresses are&nbsp;guaranteed to be valid and in the format of&nbsp;<code>"name1@name2.name3".</code></p>



<p>To mask an email,&nbsp;<strong>all names must be converted to lowercase</strong>&nbsp;and&nbsp;<strong>all letters between the first and last letter of the first name</strong>&nbsp;must be replaced by 5 asterisks&nbsp;<code>'*'</code>.</p>



<p><br><strong>2. Phone number:</strong></p>



<p>A phone number is a string consisting of&nbsp;only the digits&nbsp;<code>0-9</code>&nbsp;or the characters from the set&nbsp;<code>{'+', '-', '(', ')', '&nbsp;'}.</code>&nbsp;You may assume a phone&nbsp;number contains&nbsp;10 to 13 digits.</p>



<p>The last 10 digits make up the local&nbsp;number, while the digits before those make up the country code. Note that&nbsp;the country code is optional. We want to expose only the last 4 digits&nbsp;and mask all other&nbsp;digits.</p>



<p>The local&nbsp;number&nbsp;should be formatted and masked as&nbsp;<code>"***-***-1111",&nbsp;</code>where&nbsp;<code>1</code>&nbsp;represents the exposed digits.</p>



<p>To mask a phone number with country code like&nbsp;<code>"+111 111 111 1111"</code>, we write it in the form&nbsp;<code>"+***-***-***-1111".</code>&nbsp; The&nbsp;<code>'+'</code>&nbsp;sign and the first&nbsp;<code>'-'</code>&nbsp;sign before the local number should only exist if there is a country code.&nbsp; For example, a 12 digit phone number mask&nbsp;should start&nbsp;with&nbsp;<code>"+**-"</code>.</p>



<p>Note that extraneous characters like&nbsp;<code>"(", ")", " "</code>, as well as&nbsp;extra dashes or plus signs not part of the above formatting scheme should be removed.</p>



<p>Return the correct &#8220;mask&#8221; of the information provided.</p>



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



<pre class="wp-block-preformatted; crayon:false"><strong>Input: </strong>"LeetCode@LeetCode.com"
<strong>Output: </strong>"l*****e@leetcode.com"
<strong>Explanation:&nbsp;</strong>All names are converted to lowercase, and the letters between the
&nbsp;            first and last letter of the first name is replaced by 5 asterisks.
&nbsp;            Therefore, "leetcode" -&gt; "l*****e".
</pre>



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



<pre class="wp-block-preformatted; crayon:false"><strong>Input: </strong>"AB@qq.com"
<strong>Output: </strong>"a*****b@qq.com"
<strong>Explanation:&nbsp;</strong>There must be 5 asterisks between the first and last letter 
&nbsp;            of the first name "ab". Therefore, "ab" -&gt; "a*****b".
</pre>



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



<pre class="wp-block-preformatted; crayon:false"><strong>Input: </strong>"1(234)567-890"
<strong>Output: </strong>"***-***-7890"
<strong>Explanation:</strong>&nbsp;10 digits in the phone number, which means all digits make up the local number.
</pre>



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



<pre class="wp-block-preformatted; crayon:false"><strong>Input: </strong>"86-(10)12345678"
<strong>Output: </strong>"+**-***-***-5678"
<strong>Explanation:</strong>&nbsp;12 digits, 2 digits for country code and 10 digits for local number. 
</pre>



<p><strong>Notes:</strong></p>



<ol><li><code>S.length&nbsp;&lt;=&nbsp;40</code>.</li><li>Emails have length at least 8.</li><li>Phone numbers have length at least 10.</li></ol>



<h2><strong>Solution: String</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, running time: 4 ms, 8.4 MB
class Solution {
public:
  string maskPII(string S) {    
    return isalpha(S[0]) ? maskEmail(S) : maskPhone(S);
  }
private:
  string maskEmail(const string&amp; s) {    
    string email = s.substr(0, 1) + &quot;*****&quot; + s.substr(s.find('@') - 1);
    transform(begin(email), end(email), begin(email), ::tolower);
    return email;
  }
  
  string maskPhone(const string&amp; s) {
    string d;
    for (char c : s) if (isdigit(c)) d += c;
    string phone; 
    if (d.length() &gt; 10)
      phone += &quot;+&quot; + string(d.length() - 10, '*') + &quot;-&quot;;
    phone += &quot;***-***-&quot; + d.substr(d.length() - 4);
    return phone;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-831-masking-personal-information/">花花酱 LeetCode 831. Masking Personal Information</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/string/leetcode-831-masking-personal-information/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 929. Unique Email Addresses</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-929-unique-email-addresses/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-929-unique-email-addresses/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 28 Oct 2018 15:30:05 +0000</pubDate>
				<category><![CDATA[Hashtable]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[hashatable]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4221</guid>

					<description><![CDATA[<p>Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-929-unique-email-addresses/">花花酱 LeetCode 929. Unique Email Addresses</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>Every email consists of a local name and a domain name, separated by the @ sign.</p>
<p>For example, in <code>alice@leetcode.com</code>, <code>alice</code> is the local name, and <code>leetcode.com</code> is the domain name.</p>
<p>Besides lowercase letters, these emails may contain <code>'.'</code>s or <code>'+'</code>s.</p>
<p>If you add periods (<code>'.'</code>) between some characters in the <strong>local name</strong> part of an email address, mail sent there will be forwarded to the same address without dots in the local name.  For example, <code>"alice.z@leetcode.com"</code> and <code>"alicez@leetcode.com"</code> forward to the same email address.  (Note that this rule does not apply for domain names.)</p>
<p>If you add a plus (<code>'+'</code>) in the <strong>local name</strong>, everything after the first plus sign will be <strong>ignored</strong>. This allows certain emails to be filtered, for example <code>m.y+name@email.com</code> will be forwarded to <code>my@email.com</code>.  (Again, this rule does not apply for domain names.)</p>
<p>It is possible to use both of these rules at the same time.</p>
<p>Given a list of <code>emails</code>, we send one email to each address in the list.  How many different addresses actually receive mails?</p>
<p><strong>Example 1:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-1-1">["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]</span>
<strong>Output: </strong><span id="example-output-1">2</span>
<strong>Explanation:</strong> "<span id="example-input-1-1">testemail@leetcode.com" and "testemail@lee.tcode.com" </span>actually receive mails
</pre>
<p>&nbsp;</p>
<p><strong>Note:</strong></p>
<ul>
<li><code>1 &lt;= emails[i].length &lt;= 100</code></li>
<li><code>1 &lt;= emails.length &lt;= 100</code></li>
<li>Each <code>emails[i]</code> contains exactly one <code>'@'</code> character.</li>
</ul>
<p>&nbsp;</p>
<h1><strong>Solution: </strong></h1>
<p>Time complexity: O(n*l)<br />
Space complexity: O(n*l)</p>
<p><div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">
</p><pre class="crayon-plain-tag">// Author: Huahua, 24 ms
class Solution {
public:
  int numUniqueEmails(vector&lt;string&gt;&amp; emails) {
    unordered_set&lt;string&gt; s;
    for (const string&amp; email : emails) {
      string e;
      bool at = false;
      bool plus = false;
      for (char c : email) {
        if (c == '.') {
          if (!at) continue;
        } else if (c == '@') {
          at = true;          
        } else if (c == '+') {
          if (!at) {
            plus = true;
            continue;
          }
        }        
        if (!at &amp;&amp; plus) continue;
        e += c;        
      }      
      s.insert(std::move(e));
    }
    return s.size();
  }
};</pre><p></div></div></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-929-unique-email-addresses/">花花酱 LeetCode 929. Unique Email Addresses</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/string/leetcode-929-unique-email-addresses/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
