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. ssh远程登陆和MTR测试

    ssh -p 22 root@142.234.255.66 which mtr yum install mtr -y mtr -c 20 -n --report www.baidu.com mtr - ...

  2. obs studio 使用

    专业,开源,无广告,免费,录屏/推流神器--obs studio 稍微简单的也有captura, 原理:调用本地API获取音频流,图像流(全屏幕,单个windows窗口的图像输出)->开源音视频 ...

  3. [Hibernate] 通过 properties 类和 hql 语句进行动态查询

    //需要保证Emp和EmpProperties中的setter和getter以及属性以及 参数占位符(:eName) 的一致//动态查询 @Test public void test4(){ EmpP ...

  4. 《SQL 基础教程》第四章:数据更新

    数据更新包括了表存在的情况下数据的添加,数据的删除和数据的更新,主要是下面三个语句: INSERT 语句 DELETE 语句 UPDATE 语句 在本章的最后,讲了关于「事务」的相关知识,用于对作出的 ...

  5. kibana升级之后原本保存的数据dashboards, visualizations, index patterns丢失

    1,es升级注意的问题:https://www.elastic.co/guide/en/elasticsearch/reference/6.5/rolling-upgrades.html 2,kiba ...

  6. scrapy中XMLFeedSpider

    爬取案例: 目标网站: url = 'http://www.chinanews.com/rss/scroll-news.xml' 页面特点: 先创建爬虫项目: 也可以查看爬虫类: 创建xmlFeed ...

  7. redis的发布订阅、持久化存储、redis的主从复制

    redis的发布订阅 1. 创建redis配置文件 vim /opt/redis_conf/reids-6379.conf mkdir /data/6379 redis-server  redis-6 ...

  8. 图论++【洛谷p1744】特价采购商品&&【一本通1342】最短路径问题

    (虽然题面不是很一样,但是其实是一个题qwq) [传送门] 算法标签: 利用Floyed的o(n3)算法: (讲白了就是暴算qwq) 从任意一条单边路径开始.所有两点之间的距离是边的权,或者无穷大,如 ...

  9. 『TensorFlow』卷积层、池化层详解

    一.前向计算和反向传播数学过程讲解

  10. SAP跳过权限检查/前提是有debug权限

    SE37,AUTH_CHECK_TCODE加断点: 执行事务代码,进入断点,修改sy-subrc = 0,执行,就可以跳过权限检查. 只给了事务代码权限,没有操作权限: CL_SUID_TOOLS== ...