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. 【PAT甲级】1117 Eddington Number (25分)

    题意: 输入一个正整数N(<=100000),接着输入N个非负整数.输出最大的整数E使得有至少E个整数大于E. AAAAAccepted code: #define HAVE_STRUCT_TI ...

  2. [HNOI2013] 游走 - 概率期望,高斯消元,贪心

    假如我们知道了每条边经过的期望次数,则变成了一个显然的贪心.现在考虑如何求期望次数. 由于走到每个点后各向等概率,很显然一条边的期望次数可以与它的两个端点的期望次数,转化为求点的期望次数 考虑每个点对 ...

  3. C++-new 的六种重载形式

    当写出这样的代码的时候, 实际上有两步操作: p = new P(); 1.分配内存, 2.然后在分配好的内存之上初始化类成员. 第二步是有构造函数完成的, 第一步就是new函数的工作. 全局的new ...

  4. amazon 1

    # 跨境电商 Amazon 丰富强大的海外站 开店流程 https://www.cifnews.com/article/48921 注册事项以及二审怎么过 https://www.cifnews.co ...

  5. 使用vue实现复选框单选多选

    界面样式: <div class="right_con" v-if="isClickApply" style="border:none" ...

  6. es 6.x scroll用法

    我们可以使用from +size来获取所有数据,但是,如果数据量大的时候,这样的操作开销很大,这时候可以使用scroll操作 1.第一步发起一个scroll 的post请求,带上参数scroll=1m ...

  7. sqlserver数据库导入大批量数据

    参考: https://www.cnblogs.com/zhangliangzlee/p/3585862.html

  8. Go_json

    package main import ( "encoding/json" "fmt" ) // 结构体与json // 1.序列化: 把Go语言中的结构体变量 ...

  9. python SMTP发邮件

    # from email.mime.text import MIMEText from email.header import Header import smtplib # sender = 'zc ...

  10. @RequestMapping(value = {"list", ""})

    https://www.cnblogs.com/tongs/p/7486478.html   @RequestMapping是请求路径的注解 里面写两个value就是,路径可以是这两个, 第二个空,是 ...