LeetCode题解之Unique Email Addresses
1、题目描述

2、问题分析
将字符串中的 ‘.’ 去掉,将 ‘+’后面直到‘@’的字符串去掉,然后利用set的特性。
3、代码
int numUniqueEmails(vector<string>& emails) {
if (emails.size() == || emails.size() == )
return emails.size();
set<string> se;
for (vector<string>::iterator it = emails.begin(); it != emails.end(); it++) {
string s = *it;
auto itr = s.begin();
auto itp = s.begin();
bool isplus = false;
while (*itr != '@') {
if (*itr == '.') {
s.erase(itr-s.begin(),);
}
if (*itr == '+') {
itp = itr;
while (*itr != '@')
itr++;
s.erase(itp, itr);
break;
}
itr++;
}
se.insert(s);
}
return se.size();
}
LeetCode题解之Unique Email Addresses的更多相关文章
- 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 ...
- 【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 (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- 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< ...
- [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 - Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
随机推荐
- C#基础篇八构造函数和面向对象思想
3.关于 对象创建的几个关键词 Dog d1 = new Dog(); Dog d1 叫做 声明变量 new Dog() 叫做 实例化(创建)对象 4.关于对象.方法和 this 的关系 Dog d1 ...
- DataSet 多表关系
protected void Page_Load(object sender, EventArgs e) { string connectionString = @"Data Source= ...
- 软件架构设计学习总结(15):远程通信(RPC,Webservice,RMI,JMS、EJB、JNDI的区别)对比
总结这些概念都是易混淆,最基本概念定义复习和深入理解,同时也是架构师必备课程 RPC(Remote Procedure Call Protocol) RPC使用C/S方式,采用http协议,发送请 ...
- SSH-公私钥认证
Linux下SSH的认证方式有两种,即密码认证和公私钥认证. 我们在日常的安全维护中,出于安全的考虑,密码不明文存放,会使用公私钥认证方式.这个时候我们就需要使用ssh-keygen,ssh-keyg ...
- VGG 论文研读
VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION 论文地址 摘要 研究主要贡献是通过非常小的3x3卷积核的神经网络架 ...
- android开发学习笔记系列(5)--fragment与viewpage
前言 在前面的博客写到我针对一个项目完成了动态布局的效果,顿时感觉很爽,那么下面我针对我在前文中所讲的tabhost的实现做出一个新的方法,tabhost基本已经被启用,现在基本使用Fragment与 ...
- Core Animation之CABasicAnimation(基础动画)
#import "ViewController.h" @interface ViewController () @property(nonatomic,strong)UIButto ...
- 任意的组合,数组或数组,数组或list,list或list不用循环得出匹配的总数和需要的字段列
var res = list.Where(p=> list2.Any(x=>x.Id == p.Id));var count = res.Count();var ids = res.Sel ...
- $.ajax()参数详解及标准写法(转)
1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...
- winform 窗体中 Time 控件的用法
作用: 用于背景进程中.通过引发Timer事件,Timer控件可以有规律的隔一段时间执行一次代码.也就是,你可以根据你自己的需要,给Timer控件设置时间,Timer每隔这段时间,就执行一次代码. 属 ...