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. 杭电oj 2072————统计单词数(java)

    problem:统计单词数 思路:利用HashMap的特性——不能反复存储同一个键得数据,所以可以保证map里边儿的元素都是不重复的,存储完毕之后直接输出size就好了 注意事项: 1.利用strin ...

  2. window使用pycharm远程连接服务器

    1.进入pycharm, File->Settings->Deployment下: 1.新加一个Server,type为SFTP,name自定义一个,例如UI自动化项目: 2.在SFTP ...

  3. python3练习100题——018

    原题链接:http://www.runoob.com/python/python-exercise-example18.html 题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个 ...

  4. python3练习100题——011

    原题链接:http://www.runoob.com/python/python-exercise-example11.html 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔 ...

  5. 前端必备 Nginx 配置

    Nginx (engine x) 是一个轻量级高性能的HTTP和反向代理服务器,同时也是一个通用 代理服务器 (TCP/UDP/IMAP/POP3/SMTP),最初由俄罗斯人Igor Sysoev编写 ...

  6. MySql -- not null 非空约束

    2.not null 非空约束 用于确保当前列的值不为空:在创建表时,如果不指定是否可以为空,字段默认可以为NULL. -- 这是上一篇默认约束创建的表 CREATE TABLE `test`.`us ...

  7. 题解【洛谷P1807】最长路_NOI导刊2010提高(07)

    题面 题解 最长路模板. 只需要在最短路的模板上把符号改一下\(+\)初值赋为\(-1\)即可. 注意一定是单向边,不然出现了正环就没有最长路了,就好比出现了负环就没有最短路了. 只能用\(SPFA\ ...

  8. MP3 文件格式解析

    目录: 1.mp3 文件简介 2.ID3 tag id3 v2 3.音频帧 要注意的地方 4.参考 5.一个临时解析方法 一.MP3文件简介 MP3(mpeg-1 Ⅲ 或者 mpeg-2 Ⅲ)是一种将 ...

  9. 212. 单词搜索 II

    Q: 给定一个二维网格 board 和一个字典中的单词列表 words,找出所有同时在二维网格和字典中出现的单词. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻" ...

  10. spring jdbcTemplate query 返回值为null

    spring jdbcTemplate query 返回值为null 今天使用以下方法从数据库中查询数据,返回列表 public List<BookBean> getBooks(){ St ...