题目如下:

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.

解题思路:82%的通过率足以证明这题有多简单。把local name的 '.'替换成'',并且截断第一个'+'后面的内容即可。

代码如下:

class Solution(object):
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
dic = {}
for i in emails:
e = i.split('@')
e[0] = e[0].replace('.','')
if '+' in e[0]:
e[0] = e[0][:e[0].index('+')]
if e[0] + '@' + e[1] not in dic:
dic[e[0] + '@' + e[1]] = 1
#print dic
return len(dic)

【leetcode】929. Unique Email Addresses的更多相关文章

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

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

  2. 【Leetcode_easy】929. Unique Email Addresses

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

  3. 929. Unique Email Addresses

    929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...

  4. 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)

    [LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...

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

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

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

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

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

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

  8. LeetCode 929.Unique Email Addresses

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

  9. LeetCode 929 Unique Email Addresses 解题报告

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

随机推荐

  1. 百度小程序-form表单点击提交,input框内容不会清空

    百度小程序与微信小程序相似度90%.微信小程序转换为百度小程序,部分还是需要人工修改! 做了一个form留言表单,点击提交之后,input框第一次会清空,但是第二次就不会清空了! 不多说直接上代码! ...

  2. linux 文件及目录结构体系

    linux 目录的特点: 1). /是所有目录的顶点 2).目录结构像一颗倒挂的树 3).目录和磁盘分区是没有关联的 4)./下不同的目录可能对应不同的分区或磁盘 5).所有的目录都是按照一定的类别有 ...

  3. Delphi ListView的用法

    //增加 i := ListView1.Items.Count; with ListView1 do begin ListItem:=Items.Add; ListItem.Caption:= Int ...

  4. LUOGU P3759 [TJOI2017]不勤劳的图书管理员(树套树)

    传送门 解题思路 和以前做过的一道题有点像,就是区间逆序对之类的问题,用的是\(BIT\)套权值线段树,交换时讨论一下计算答案..跑的不如暴力快.. 代码 #include<iostream&g ...

  5. window 安装VisualSvn Server

    VisualSvn Server 1 .VisualSvn Server  介绍和下载 VisualSvn Server是免费的,而VisualSvn是收费的.VisualSvn是Svn的客户端,和V ...

  6. Scribd每月共有超过两亿个访客、累积数亿篇以上的文件档案,Alexa全球排名200以内

    目前已登上世界300大网站,每月共有超过两亿个访客.累积数亿篇以上的文件档案.透过Flash介面的阅读器-iPaper,使用者可以在网站内浏览各种文件,由于该网站是一个文件分享平台,所有的文件都是由使 ...

  7. bootstrap基础模板页面,详细注释

    ​ <!--html5 骨架--> <!DOCTYPE html> <!--语言是中文简体--> <html lang="zh-cn"&g ...

  8. PAT 2019-3 7-3 Telefraud Detection

    Description: Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, ...

  9. 在WSL Ubuntu 下编译UPX详细步骤

    准备环境: 1. sudo apt-get update 2. sudo apt-get clang 3. apt-get install libstdc++-dev Reading package ...

  10. Java实验报告(四)&第六周学习总结

    班级 计科二班 学号 20188425 姓名 IM 完成时间2019/10/07 评分等级 一.实验目的 (1)掌握类的继承 (2)变量的继承和覆盖,方法的继承,重载和覆盖的实现: 二.实验的内容 ( ...