929. Unique Email Addresses
22766FavoriteShare
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 <= 100
1 <= emails.length <= 100
- Each
emails[i]
contains exactly one'@'
character.
class Solution {
public: int numUniqueEmails(vector<string>& emails) {
map<string,int> m1;
int point,add,at;
for(auto &astr:emails){
at=findc(astr,'@',,astr.length()-);
if(at!=-){
while( (add=findc(astr,'+',,at)) !=-){
astr.erase(add,at-add);
at-=(at-add);
}
}
while( (point=findc(astr,'.',,at)) != -){
astr.erase(point,);
at-=;
}
m1[astr]++;
}
return m1.size();
}
int findc(string str,char c,int start,int end){
for(int i=start;i<=end;i++){
if(str[i]==c) return i;
}
return -;
} };
最新文章
- SQL Server中的高可用性(2)----文件与文件组
- javaweb写的在线聊天应用
- JSoup笔记
- MySQL导入.sql文件及常用命令
- VPN推荐
- Django1.9开发博客(12)- i18n国际化
- hdu 5821 (贪心排序) Ball
- CSS 兼容 总结
- cocos2dx中的动作
- PostgreSQL的 initdb 源代码分析之二
- MySQL之删_delete-truncate
- Git 安装及用法 github 代码发布 gitlab私有仓库的搭建
- Django 设置media static
- LeetCode(5):最长回文子串
- python之常用字符串用法
- array_map,array_filter,array_walk区别
- Linux内核分析作业 NO.2
- ==、is
- [日常] 编写HTTP接口文档
- 几个不同版本的framework改进
热门文章
- RandomAccessFile出现中文乱码问题
- $(document).ready和window.onload的区别
- jmeter发起form-data格式
- fiddler抓包——IOS
- ROS与C++
- 【java】java基本用法记录
- 《剑指offer》二叉树的深度
- PADS Layout VX.2.3 出Gerber文件时遇到一个奇怪的现象
- NAT穿透解决
- [原创]基于Zynq SDIO WIFI 2.4G/5G SotfAP STA