929. Unique Email Addresses*

https://leetcode.com/problems/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.
  • All local and domain names are non-empty.
  • Local names do not start with a '+' character.

C++ 实现 1

哈希表. 这道题需要注意额外的操作(比如遇到 . 或者 +)都是在 local name 中进行的, 因此代码中使用 is_local_name 判断当前是否在 local name 中.

class Solution {public:int numUniqueEmails(vector<string>& emails) {unordered_set<string> record;for (auto &email : emails) {string valid_email;int i = 0;bool is_local_name = true;while (i < email.size()) {if (email[i] == '@') is_local_name = false;if (email[i] == '.' && is_local_name) {++ i;} else if (email[i] == '+' && is_local_name) {while (i < email.size() && email[i] != '@') ++ i;} else {valid_email += email[i++];}}record.insert(valid_email);}return record.size();}
};

929. Unique Email Addresses*相关推荐

  1. Rust LeetCode 练习:929 Unique Email Addresses

    LeetCode 929 Unique Email Addresses 题目大意:邮箱地址格式为[本地名]@[域名],其中[本地名]存在+和.两种特殊情况.现在输入一组邮箱地址,要求进行如下处理,然后 ...

  2. LeetCode: 929. Unique Email Addresses

    051301 题目 Every email consists of a local name and a domain name, separated by the @ sign. For examp ...

  3. 2019年2月26日 Unique Email Addresses、To Lower Case、Encode and Decode TinyURL

    今天开始加快速度,趁着还有空多刷几题,语言换成python提高速度了. 1. Unique Email Addresses 弱题,注意@符号前后的处理方式不同 class Solution(objec ...

  4. LeetCode 929 Unique Email Addresses--python一行解法,Java解法

    题目地址:Unique Email Addresses - LeetCode Every email consists of a local name and a domain name, separ ...

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

    Leetcode 929.独特的电子邮件地址 1 题目描述(Leetcode题目链接)   每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.co ...

  6. Unique Email Addresses

    Given a list of emails, we send one email to each address in the list.  How many different addresses ...

  7. Leetcode929.Unique Email Addresses独特的电子邮件地址

    每封电子邮件都由一个本地名称和一个域名组成,以 @ 符号分隔. 例如,在 alice@leetcode.com中, alice 是本地名称,而 leetcode.com 是域名. 除了小写字母,这些电 ...

  8. Sicily.Handling e-mail addresses

    Description Time Limit: 1sec    Memory Limit:256MB You've gathered some e-mail addresses from a vari ...

  9. LeetCode 所有题目总结

    文章目录 做题注意事项 题目分类 1.位运算 2.字符串题型 3.TopK 问题--最大堆/最小堆 4.链表 5.动态规划 easy Medium hard 6.贪心 7.树 8.图 9.数学题 10 ...

最新文章

  1. Meta标签中的format-detection属性及含义
  2. 自己动手编写tomcat服务器(三)
  3. 如何使VS2008 调试网站的根目录和IIS调试的一致?
  4. 第六届上海市大学生网络安全大赛 | Wp
  5. change element 原始值_change-element
  6. Ajax Step By Step1
  7. java 泛型参数_[基础]-Java泛型
  8. dell装双系统linux系统,记录DELL灵越7590/7591安装Ubuntu+Win10双系统
  9. gis导出栅格数据为什么不能tif_GIS基础操作教程(3)--点数据操作【附带练习数据】...
  10. his提供哪些服务_论文查重检测系统提供哪些服务
  11. 浙大计算机学硕名额,浙大计算机学硕复试线399分,专硕375,不愧被称为“炸大”...
  12. Java开发自学教程!java从入门到精通txt下载
  13. iOS 音频视频播放器实现边下载边播放缓存视频
  14. oracle排除非数字,oracle字段中找出字段中含有非数字的方法!!!
  15. Cabbage教学(5)——条件体
  16. vue-cli中出现这个错误[WDS] Disconnected!解决!!!
  17. 【转】免费进入学术数据库
  18. win10添加计算机语言,Win10添加语言包报错“0x800F0950”怎么办?
  19. python每日学4:vscode的安装与基础使用
  20. WebDay14 Linux高级+Nginx

热门文章

  1. selenium自动化测试学习4-基本控件介绍
  2. 如何翻译图片?这些实用方法值得收藏
  3. static不应在文件范围内定义的成员函数上使用
  4. Qt 实时读串口数据,并将读到的数据从网口发送出去
  5. codeblocks shotcut
  6. vue+elementUI中使用Echarts (懒人无脑版)
  7. 重拾编程之路--jeetcode(java)--Range Sum Query - Immutable
  8. alv布局 sap_ALV详解_SAP精华篇.pdf
  9. FBAlpha编译和裁剪笔记
  10. HDU3003 Pupu,快速幂取模