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? 

Example 1:

Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
Output: 2
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails

Hash

class Solution {
public int numUniqueEmails(String[] emails) {
if(emails == null || emails.length == 0){
return 0;
}
Set<String> set = new HashSet<>();
for(String email : emails){
String[] strs = email.split("@");
String localName = strs[0];
String domainName = strs[1];
StringBuilder sb = new StringBuilder();
for(char c : localName.toCharArray()){
if(c == '.'){
continue;
}
else if(c == '+'){
break;
}
else{
sb.append(c);
}
}
set.add(sb.toString() + "@" + domainName);
}
return set.size();
}
}

LeetCode - Unique Email Addresses的更多相关文章

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

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

  2. 929. Unique Email Addresses

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

  3. 【Leetcode_easy】929. Unique Email Addresses

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

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

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

  5. LeetCode 929.Unique Email Addresses

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

  6. LeetCode 929 Unique Email Addresses 解题报告

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

  7. 108th LeetCode Weekly Contest Unique Email Addresses

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

  8. 【leetcode】929. Unique Email Addresses

    题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...

  9. [LeetCode] 929. Unique Email Addresses 独特的邮件地址

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

随机推荐

  1. 浅谈Static

    A: 使用场景 static可以修饰成员变量和成员方法. 什么时候使用static修饰成员变量? 加static修饰成员的时候,这个成员会被类的所有对象所共享.一般我们把共性数据定义为静态的变量 什么 ...

  2. POI 导入excel 代码记录 方便以后粘贴

    import java.io.FileInputStream; import java.io.InputStream; import javax.annotation.Resource; import ...

  3. 00-python-常用命令

    1. pip 加速命令 pip install --index-url https://pypi.douban.com/simple 或者 pip install -i https://pypi.tu ...

  4. 使用pandas的部分问题汇总

    pandas(我所用版本0.17)是一个强大数据处理库,在开发金融类系统中我应用到了pandas.Dataframe数据类型,它的数据结构类似一张图表(如下图所示),左边一列为index既行的索引: ...

  5. HDU - 1575——矩阵快速幂问题

    HDU - 1575 题目: A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973.  Input数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n( ...

  6. 『OpenCV3』滤波器实现及使用滤波器降噪

    一.滤波器实现 我们实现这样一个基于拉普拉斯算子的滤波器核心,并使用它进行滤波,这可以做到锐化图像的效果, 0 -1 0 -1 5 -1 0 -1 0 首先我们完全手动的进行滤波,依赖指针操作, vo ...

  7. 使用python来访问Hadoop HDFS存储实现文件的操作

    原文:http://rfyiamcool.blog.51cto.com/1030776/1258292 在调试环境下,咱们用hadoop提供的shell接口测试增加删除查看,但是不利于复杂的逻辑编程 ...

  8. elinks快捷方式

    突然有兴趣看看Linux下的字符模式的浏览器,搜了下有好几个,在Ubuntu里“添加/删除”里找到一个,叫Elinks,安装,然后在终端运行elinks,试用了一下,不错,使用方法也挺简单的,支持多标 ...

  9. jQueryValidate的表单提交ajax刷新代码

    $("#form-member-add").validate({ rules:{ username:{ required:true, minlength:2, maxlength: ...

  10. linux c使用socket进行http 通信,并接收任意大小的http响应(四)

    终于说到SOCKET 这里了.SOCKET进行http通信的实际就是利用socket将http请求信息发送给http服务器,然后再利用socket接收http响应. 由于本文与之通信的服务器是ip已知 ...