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 ...
随机推荐
- Selenium自动化测试Python二:WebDriver基础
WebDriver基础 欢迎阅读WebDriver基础讲义.本篇讲义将会重点介绍Selenium WebDriver的环境搭建和基本使用方法. WebDriver环境搭建 Selenium WebDr ...
- js获取上一个兄弟元素
需要用到的两个属性:previousSbiling和previousElementSibling previousSibling:获取元素的上一个兄弟节点:(既包含元素节点.文本节点.注释节点) pr ...
- logstash-3-输出到es中
之前测试 filebeat和logstash的时候, 使用的是stdout标准输出, 现在我们想把数据输出到es中去, 1, 首先需要一个es: 修改配置文件 后台启动 ./bin/elasticse ...
- php实现请求分流
一个请求,同时分发到多个服务器, 正常的是: A ============> B 现在想实现的是: --------------> C A ======> B ----- ...
- Java并发编程-ReentrantLock源码分析
一.前言 在分析了 AbstractQueuedSynchronier 源码后,接着分析ReentrantLock源码,其实在 AbstractQueuedSynchronizer 的分析中,已经提到 ...
- RSA实现前端数据加密
一.前言 一般在登录注册的时候,不能以明文的方式传递数据到后台,如果是http下,很容易被劫持.所以对数据进行加密是常规做法. 二.RSA算法 ”RSA加密算法是一种非对称加密算法.对极大整数做因数分 ...
- git remote: HTTP Basic: Access denied 错误解决办法
问题描述: git push 报 HTTP Basic: Access denied 错误 原因:本地git配置的用户名.密码与gitlabs上注册的用户名.密码不一致. 解决方案: 1. 如果账号密 ...
- sqlserver查询连续签到天数
create table #t(keyId int identity,actionDate datetime)insert into #t(actionDate) select distinct Cr ...
- C# 全文搜索Lucene
全文出自:https://blog.csdn.net/huangwenhua5000/article/details/9341751 1 lucene简介1.1 什么是luceneLucene是一个全 ...
- 1.C#知识点:值类型和引用类型
一.什么是值类型?什么引用类型? 1.值类型的值是存储在栈上的.引用类型是存在堆上的. 2.值类型变量声明之后,不管是否已经分配内存,编译器在堆上为其分配内存. 3.引用类型声明的时候,这时候只在 ...