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 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) {
set<string>Set;
int len = emails.size();
string strlen="";
string x="";
int flag=;
int j=;
int y=;
int Jstr;
for(int i=;i<len;i++){ strlen = emails[i]; flag = ;
j = ;
y = ;
x = "";
Jstr = strlen.length();
while(strlen[j]!='@'){
j++;
} while(y<=j){
if(strlen[y]=='.'){
y++;
}
if(strlen[y]=='+'){
break;
}
x+=strlen[y];
y++;
}
while(j<Jstr){
x+=strlen[j];
j++;
}
//cout<<x<<endl;
Set.insert(x);
}
return Set.size();
}
};
108th LeetCode Weekly Contest Unique Email Addresses的更多相关文章
- 【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题解之Unique Email Addresses
1.题目描述 2.问题分析 将字符串中的 ‘.’ 去掉,将 ‘+’后面直到‘@’的字符串去掉,然后利用set的特性. 3.代码 int numUniqueEmails(vector<string ...
- 108th LeetCode Weekly Contest Minimum Falling Path Sum
Given a square array of integers A, we want the minimum sum of a falling path through A. A falling p ...
- 108th LeetCode Weekly Contest Binary Subarrays With Sum
In an array A of 0s and 1s, how many non-empty subarrays have sum S? Example 1: Input: A = [1,0,1,0, ...
- [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 Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
随机推荐
- Flask解决跨域
Flask解决跨域 问题:网页上(client)有一个ajax请求,Flask sever是直接返回 jsonify. 然后ajax就报错:No 'Access-Control-Allow-Origi ...
- 第十二课 Actionlib(1)
一\Actionlib概念 在ROS系统中,有时需发送请求给某个节点完成相应的任务,同时获得一个一个响应,这种情况下可以通过ROS服务来 完成;然而,在某些情况下,服务需要很长时间才能执行完,如让机器 ...
- MagicNotes:突破来自外界的脑力压制
MagicNotes,思绪随风飞扬,偶尔在这里停留. 在前面的<MagicNotes:如何迈向工作的坦途>里面,我们提到了在工作中应该发挥好个人的主观能动性,简单来说就是要学会主动出击.但 ...
- Requests接口测试(一)
接口测试概念 接口测试是测试系统组件间接口的一种测试.接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑依赖关 ...
- What’s the Difference Between a Value Provider and Model Binder?
ASP.NET MVC 3 introduced the ability to bind an incoming JSON request to an action method parameter, ...
- C# 抽象(3)
接上章: 抽象类中有抽象方法,那么可不可以有非抽象方法呢? 答案是可以的. abstract class Human { public abstract void Think(); public ab ...
- ES更改参数max_result_window
今天开发那边说翻页超过10000报错.早上来查阅官网手册,说from/size默认是10000.通过参数index.max_result_window进行控制.那么直接改这个参数即可. 1.先看看默认 ...
- kali 插耳机没声音
打开终端,然后输入命令:下载pulseaudio音量控制软件: apt install pavucontrol 然后终端输入指令:pavucontrol打开软件,发现在输出设备中有两个输出设备:一个N ...
- [Swift实际操作]九、完整实例-(5)创建BaseViewController作为控制器的基类
本文将给项目中的所有视图控制器,创建一份基类.该基类用来定义一些共用的属性和方法. 首先在用来放置视图控制器类的文件夹上点击鼠标右键,打开右键 菜单. 选择[New File]创建文件选项. 在弹出的 ...
- linux下Tomcat+OpenSSL配置单向&双向认证(自制证书)
背景 由于ios将在2017年1月1日起强制实施ATS安全策略,所有通讯必须使用https传输,本文只针对自制证书,但目前尚不确定自制证书是否能通过appstore审核. 1.必须支持传输层安全(TL ...