929. Unique Email Addresses
Easy

22766FavoriteShare

Every email consists of a local name and a domain name, separated by the @ sign.

For example, in alice@leetcode.comalice 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.
Accepted
46,564
Submissions
58,349
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的更多相关文章

  1. 【Leetcode_easy】929. Unique Email Addresses

    problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...

  2. [leetcode] 929. Unique Email Addresses (easy)

    统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...

  3. [LeetCode] 929. Unique Email Addresses 唯一的电邮地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  4. [LeetCode] 929. Unique Email Addresses 独特的邮件地址

    Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...

  5. LeetCode 929.Unique Email Addresses

    Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...

  6. LeetCode 929 Unique Email Addresses 解题报告

    题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...

  7. 【leetcode】929. Unique Email Addresses

    题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...

  8. 【LeetCode】929. Unique Email Addresses 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...

  9. LeetCode 929. Unique Email Addresses (独特的电子邮件地址)

    题目标签:String 题目说明 有两个规则针对于 local name. 所以先把local name 和 domain name 分开. 两个规则是: rule 1:'.' 会被去除. (利用re ...

随机推荐

  1. Python自动化中的元素定位xpath(二)

    1.Xpath元素定位 1)ele = b.find_element_by_xpath(‘/html/body/from/input[1]’) 2)Ele = b.find_element_by_xp ...

  2. 机器学习基石12-Nonlinear Transformation

    注: 文章中所有的图片均来自台湾大学林轩田<机器学习基石>课程. 笔记原作者:红色石头 微信公众号:AI有道 上一节课介绍了分类问题的三种线性模型,可以用来解决binary classif ...

  3. Gitlab_ansible_jenkins三剑客①搭建gitlab的详细步骤

    环境准备 1.关闭selinux和防火墙 [root@node1 lesson2]# vim /etc/sysconfig/selinux SELINUX=disabled # systemctl s ...

  4. redis集群结构图

    在JAVA编程时,使用哨兵池获取jedis来进行数据的操作,哨兵对对集群进行监视,当主节点宕掉时,会自动将子一个子节点升级为主节点,原来的主节点上线时会自动变为从节点,主节点的变化,对于使用哨兵池方式 ...

  5. 自己对Web标准的理解

    1.WEB标准 WEB分层: 1.结构层(HTML)   2.表现(css) 3.行为(js) web标准的优点: * 易于维护:只需更改css文件,就能改变整站的样式: * 页面响应快:HTML文档 ...

  6. verilog function功能函数写法

    :] sm2tc; :] din; :] dp; :] dn; :] dout; begin dp = {'b0, din[14:0]}; dn = ~dp + 'b1; dout = (din[] ...

  7. python3学习笔记之十七

    1.  网站本质:通过socket建立连接. 服务端(网站) 1.  先启动并监听:80端口 4.  获取请求信息 请求头 请求体 5.  处理请求 响应内容: 响应头:\r\n\r\n响应体     ...

  8. python中thread的setDaemon、join的用法的代码

    下面内容是关于python中thread的setDaemon.join的用法的内容. #! /usr/bin/env python import threading import time class ...

  9. php Excel 导入功能

    下载excel类地址 https://pan.baidu.com/s/19MqAHUn4RyZ5HEAChyC0jg  密码:mn58 本人用的thinkcmf框架 把类文件放在框架的类文件里面,下面 ...

  10. Windows下安装Redis客户端

    Redis是有名的NoSql数据库,一般Linux都会默认支持.但在Windows环境中,可能需要手动安装设置才能有效使用.这里就简单介绍一下Windows下Redis服务的安装方法,希望能够帮到你. ...