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 name.

Besides lowercase letters, these emails may contain '.'s or '+'s.

If you add periods ('.') between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address. (Note that this rule does not apply for domain names.)

If you add a plus ('+') in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered, for example m.y+name@email.com will be forwarded to my@email.com. (Again, this rule does not apply for domain names.)

It is possible to use both of these rules at the same time.

Given a list of emails, we send one email to each address in the list. How many different addresses actually receive mails?

每封电子邮件由一个本地名称和一个域名组成,以@符号分隔。

例如,在alice@leetcode.com中,alice是本地名,leetcode.com是域名。

除了小写字母,这些邮件还可能包含' '。”或“+”。

如果您在电子邮件地址的本地名称部分的某些字符之间添加句点('.'),那么发送到那里的邮件将被转发到相同的地址,而本地名称中没有点号。例如,“alice.z@leetcode.com”和“alicez@leetcode.com”转发到相同的电子邮件地址。(请注意,此规则不适用于域名。)

如果在本地名称中添加加号('+'),第一个加号后面的所有内容都将被忽略。这允许某些电子邮件被过滤,例如m.y+name@email.com将被转发到my@email.com。(同样,这条规则不适用于域名。)

同时使用这两个规则是可能的。

给定一个电子邮件列表,我们向列表中的每个地址发送一封电子邮件。有多少不同的地址实际接收邮件?

class Solution {
public int numUniqueEmails(String[] emails) {
Set<String> hs=new HashSet();
for(String s:emails)
{
int count1=s.indexOf('@');
String local=s.substring(0,count1);
String rest=s.substring(count1); if(local.contains("+")){
local=local.substring(0,local.indexOf('+'));
}
local=local.replaceAll(".","");
s=local+rest;
hs.add(s);
}
return hs.size();
}
}

  

leetcode929 Unique Email Addresses的更多相关文章

  1. Leetcode929.Unique Email Addresses独特的电子邮件地址

    每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...

  2. 929. Unique Email Addresses

    929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...

  3. [leetcode] 929. Unique Email Addresses (easy)

    统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...

  4. 【Leetcode_easy】929. Unique Email Addresses

    problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...

  5. [Swift]LeetCode929. 独特的电子邮件地址 | Unique Email Addresses

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  6. [LeetCode] 929. Unique Email Addresses 唯一的电邮地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  7. LeetCode 929.Unique Email Addresses

    Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...

  8. LeetCode - Unique Email Addresses

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  9. LeetCode 929 Unique Email Addresses 解题报告

    题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...

随机推荐

  1. EntityFramework之原始查询及性能优化

    之前做海信项目,数据量自交大,为了提高查询效率用的 https://www.cnblogs.com/CreateMyself/p/4746258.html

  2. style.display = "inline或inline";和style.display = "";的区别

    function a(){ if($('#b').attr('checked')){ $('.c').css("display",""); //"di ...

  3. git 解决每次更新代码都要输入用户名密码

    git config --global credential.helper store git pull /git push (第一次输入,后续就不用再次数据)

  4. Hibernate:Hibernate缓存策略详解

    一:为什么使用Hibernate缓存: Hibernate是一个持久层框架,经常访问物理数据库. 为了降低应用程序访问物理数据库的频次,从而提高应用程序的性能. 缓存内的数据是对物理数据源的复制,应用 ...

  5. MyEclipse 安装 emmet 插件

    1.在线安装 地址:http://download.emmet.io/eclipse/updates/ 安装完成后重新启动myeclipse 2.离线安装 下载jar包:https://github. ...

  6. \r、\n、\r\n的区别-转载

    文章地址: https://blog.csdn.net/qq_40395278/article/details/81199281 https://blog.csdn.net/qq592304796/a ...

  7. vue里不同数据的循环,其中的数组对象

    用产品的属性数据说明 页面里显示效果为:要把产品的属性显示到页面上,产品属性为后台自主上传产品的属性,产品的属性不同,所以需要把属性和属性值显示到页面上 产品属性数据为: properties: &q ...

  8. mybatis(六):设计模式 - 模板方法模式

  9. 题解【洛谷P3662】[USACO17FEB]Why Did the Cow Cross the Road II S

    本题是练习前缀和的好题!我们可以枚举前端点,确定一个长度为k的区间,然后利用前缀和统计区间内损坏的灯的数量,最后取最小值即可.AC代码: #include <bits/stdc++.h> ...

  10. Django的安装、使用详解、自动化测试应用以及程序打包

    1.Django的安装 pip install Django 验证 Django 是否能被 Python 识别 >>> import django >>> prin ...