[LeetCode] 929. Unique Email Addresses 独特的邮件地址
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
Note:
1 <= emails[i].length <= 1001 <= emails.length <= 100- Each
emails[i]contains exactly one'@'character. - All local and domain names are non-empty.
- Local names do not start with a
'+'character.
博主正在刷题的时候,突然朋友圈刷出了科比坠机的消息,惊的下巴都掉了,忙看了下日期,不是四月一啊,于是疯狂的 google,中文搜不到任何相关的消息,于是搜英文 Kobe Bryant,结果真的有坠机消息,而且是几分钟前刚发布的,渐渐的很多微信群里都开始讨论了,连 wiki 上都更新了,随着越来越多的媒体确认这一个消息,心情越来越沉重了。算起来了,在博主最早关注 NBA 的时候,科比就当红球星,二十年的光辉岁月,五座总冠军戒指,甚至退役后还获得过奥斯卡小金人,年仅四十一岁,本来是要续写另一段传奇人生,就这么的走了?人生无常啊,你永远不知道意外和明天哪一个先到来,能平平安安的活着就已经是万幸了。RIP,一路走好,科比,愿天堂没有直升机。下面带着沉重的心情来做题吧,这道题是关于邮件的,邮件名里可能会有两个特殊符号,点和加号,对于点采取直接忽略的做法,对于加号则是忽略其后面所有的东西,现在问我们有多少个不同的邮箱。没有太多的技巧,就直接遍历一下所有的字符,遇到点直接跳过,遇到 '+' 或者 '@' 直接 break 掉。注意这里其实有个坑,就是域名中也可能有点,而这个点是不能忽略的,所以要把 '@' 及其后面的域名都提取出来,连到之前处理好的账号后面,一起放到一个 HashSet 中,利用其可以去重复的特性,最终剩余的个数即为所求,参见代码如下:
class Solution {
public:
int numUniqueEmails(vector<string>& emails) {
unordered_set<string> st;
for (string email : emails) {
string name;
for (char c : email) {
if (c == '.') continue;
if (c == '+' || c == '@') break;
name.push_back(c);
}
name += email.substr(email.find('@'));
st.insert(name);
}
return st.size();
}
};
Github 同步地址:
https://github.com/grandyang/leetcode/issues/929
参考资料:
https://leetcode.com/problems/unique-email-addresses/
https://leetcode.com/problems/unique-email-addresses/discuss/317207/C%2B%2B-Concise-Solution
https://leetcode.com/problems/unique-email-addresses/discuss/186798/Java-7-liner-with-comment.
[LeetCode All in One 题目讲解汇总(持续更新中...)](https://www.cnblogs.com/grandyang/p/4606334.html)
[LeetCode] 929. Unique Email Addresses 独特的邮件地址的更多相关文章
- LeetCode 929. Unique Email Addresses (独特的电子邮件地址)
题目标签:String 题目说明 有两个规则针对于 local name. 所以先把local name 和 domain name 分开. 两个规则是: rule 1:'.' 会被去除. (利用re ...
- 【LeetCode】Unique Email Addresses(独特的电子邮件地址)
这道题是LeetCode里的第929道题. 题目要求: 每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 ...
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- LeetCode 929 Unique Email Addresses 解题报告
题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...
- [LeetCode] 929. Unique Email Addresses 唯一的电邮地址
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- LeetCode 929.Unique Email Addresses
Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...
- Leetcode929.Unique Email Addresses独特的电子邮件地址
每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
随机推荐
- Java生鲜电商平台-小程序或者APP拼团功能设计与架构实战
Java生鲜电商平台-小程序或者APP拼团功能设计与架构实战 说明:Java生鲜电商平台拼团是拉新引流的利器,将拼团运用到极致的就是拼多多,前期通过选取性价比高.实用性强的商品进行拼团,在社交圈(主要 ...
- Write-up-Toppo
关于 下载地址:点我 哔哩哔哩:哔哩哔哩 信息收集 vmnet8网卡,IP:192.168.131.144,开放web,ssh服务 ➜ ~ ip a show dev vmnet8 5: vmnet8 ...
- jQuery Validation Engine(二) checkHello data-errormessage
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- Spark教程——(1)安装Spark
Cloudera Manager介绍 Cloudera Manager(简称CM)是Cloudera公司开发的一款大数据集群安装部署利器,这款利器具有集群自动化安装.中心化管理.集群监控.报警 ...
- 信号强度(RSSI)知识整理
来源: https://www.cnblogs.com/lele/articles/2832885.html 为什么无线信号(RSSI)是负值 答:其实归根到底为什么接收的无线信号是负值,这样子是不是 ...
- Linux centos7 日常运维——使用w查看系统负载、vmstat命令、top命令、sar命令、nload命令
一.使用w查看系统负载 w .uptime查看系统负载,0.00表示1分钟之内负载为0 cat /proc/cpuinfo查看cpu核数 二.vmstat命令,查看进程.cpu.memory.交换. ...
- Python—处理Excel表格
一.使用xlrd和xlwt这两个库来处理excel,即xlrd是读excel的库,xlwt是写excel的库 1.使用 xlrd 读取Excel数据 # -*- coding:utf-8 -*- im ...
- 必应壁纸php获取接口
<?php if($_GET['idx']==null){ $str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx= ...
- SSH框架系列:Spring配置多个数据源
分类: [java]2013-12-09 16:59 1247人阅读 评论(0) 收藏 举报 1.问题的引入 对于普通的SSH框架而言,一般配置一个数据源,一个SessionFactory,一个事务管 ...
- eot文件
*.eot文件 是一种压缩字库,目的是解决在网页中嵌入特殊字体的难题2.在网页中嵌入的字体只能是 OpenType 类型,其他类型的字体只有转换成 OpenType 类型(eot格式)的字体才能在网页 ...