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 <= 1001 <= 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 -;
}
};
929. Unique Email Addresses的更多相关文章
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- [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, in ali ...
- [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 ...
- 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, ...
- 【LeetCode】929. Unique Email Addresses 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...
- LeetCode 929. Unique Email Addresses (独特的电子邮件地址)
题目标签:String 题目说明 有两个规则针对于 local name. 所以先把local name 和 domain name 分开. 两个规则是: rule 1:'.' 会被去除. (利用re ...
随机推荐
- C++的变量初始化
C++中变量的初始化有很多种方式,如:默认初始化,值初始化,直接初始化,拷贝初始化,列表初始化. 1.默认初始化:默认初始化是指定义变量时没有指定初值时进行的初始化操作. 如:int a:这些变量被定 ...
- boostrap日期时间插件datetimepicker使用过程的一些问题总结
1.汉化问题 虽然有转门的汉化脚本,不过如果简单使用的话自己稍微改一下源码就行了: var dates = $.fn.datetimepicker.dates = { en: { days: ['Su ...
- 2018-2019-2 网络对抗技术 20165328 Exp6 信息收集与漏洞扫描
目录 实验要求 基础问题回答: 实验过程: 各种搜索技巧的应用及DNS IP注册信息的查询 基本扫描技术 漏洞扫描--使用OpenVAS 实验感想 实验要求 (1)各种搜索技巧的应用 (2)DNS I ...
- webpack的在开发生产时的具体功能
webpack的在开发生产时的具体功能 开发时需要调试代码,在打包过后如果出错我们就需要调试工具来帮我们改正错误.Source Map就是帮我们解决这个难题的.他要在我们的webpack.config ...
- python集合操作
一:python官方文档 https://docs.python.org/3.6/library/stdtypes.html#set-types-set-frozenset 二:集合概念 集合是无序的 ...
- Useful Git Commands for me
查看Git追踪的文件 git ls-files 移除远程仓库的文件夹 git rm -r --cached some-directory git commit -m "Remove th ...
- RabbitMQ 实现远程过程调用RPC
RPC调用的顺序1. 在客户端初始化的时候,也就是SimpleRpcClient类初始化的时候,它会随机的创建一个callback队列,用于存放服务的返回值,这个队列是exclusive的.连接断开就 ...
- Oracle-分析函数之sum(...) over(...)
概述 Oracle函数 很久之前更新了一篇Oracle的函数博文http://blog.csdn.net/yangshangwei/article/details/51425458,分析函数并没有包括 ...
- autoit学习安装说明及例子
下载安装包或者绿色版本进行使用,我使用的版本是3.3.9.0 第一汉化版命令行安装 : "au3tool.exe /s" 命令行卸载 : "au3tool.exe /u& ...
- python入门编程之mysql编程
python关于mysql方面的连接编程 前提:引入mysql模块MySQLdb,即:MySQL_python-1.2.5-cp27-none-win_amd64.whl 如果要用线程池,则要引用模块 ...