题目要求

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.

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?

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

1 <= emails[i].length <= 100
1 <= emails.length <= 100
Each emails[i]contains exactly one '@' character.

题目分析及思路

题目要求得到一组邮件地址中不重复的地址的个数,规则是用户名部分有‘.’,则和无‘.’的用户名一样;用户名部分有‘+’,则忽略第一个‘+’后面的部分。两个规则可以同时生效,但对域名部分不起作用。所以先对邮件进行拆分,分为用户名部分和域名部分;之后先找到‘+’,去掉‘+’及后面部分,再去掉‘.’。最后再和‘@’及域名连接。因为要去重,所以使用一个set保存所有不重复的结果。

python代码​

class Solution:

def numUniqueEmails(self, emails):

"""

:type emails: List[str]

:rtype: int

"""

emailsset = set()

for e in emails:

local,domain = e.split("@")

local = local.split("+")[0].replace(".","")

emailsset.add(local+"@"+domain)

return len(emailsset)

LeetCode 929 Unique Email Addresses 解题报告的更多相关文章

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

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

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

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

  3. LeetCode 929.Unique Email Addresses

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

  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 独特的邮件地址

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

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

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

  7. 929. Unique Email Addresses

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

  8. 【Leetcode_easy】929. Unique Email Addresses

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

  9. 【leetcode】929. Unique Email Addresses

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

随机推荐

  1. 20款最好的jQuery文件上传插件

    当它是关于开发网络应用程序和网页的时候,文件上传功能的重要性是不容忽视的.一个文件上传功能可以让你上传所有类型的文件在网站上,包括视频,图像,文件和更多.创建一个文件上传功能,对你的网站是不是很难,有 ...

  2. 接口app 接口中上传 图片

    /** * @Method base64图片上传 * @author 黄国金 * return array * date 2016-1-10 */function saveBase64Image($b ...

  3. Java知多少(6)第一个程序示例

    跟随世界潮流,第一个Java程序输出“Hell World!”. 通过Eclipse运行程序 启动Eclipse,在菜单中选择“文件 --> 新建 --> Java项目”,弹出对话框: 图 ...

  4. Go语言_iota用法

    一.介绍 iota,特殊常量,可以认为是一个可以被编译器修改的常量. 在每一个const关键字出现时,被重置为0,然后再下一个const出现之前,每出现一次iota,其所代表的数字会自动增加1. io ...

  5. history 命令历史

    在终端中按捉[Ctrl]键的同时[r]键,出现提示:(reverse-i-search),此时你尝试一下输入你以前输入过的命令,当你每输入一个字符 的时候,终端都会滚动显示你的历史命令.当显示到你想找 ...

  6. Ant 学习笔记

    1.下载Ant 官方网站http://ant.apache.org/bindownload.cgi 下载最新版本  .zip archive: apache-ant-1.9.4-bin.zip [PG ...

  7. Linux-C实现GPRS模块发送短信

    “GSM模块,是将GSM射频芯片.基带处理芯片.存储器.功放器件等集成在一块线路板上,具有独立的操作系统.GSM射频处理.基带处理并提供标准接口的功能模块.GSM模块根据其提供的数据传输速率又可以分为 ...

  8. [转]linux 调用动态库so文件

    记录一个面试被问到的问题. extern 有什么用途? 除了多文件共享全局变量外还有呢? extern "C" 的功能? 我想看完这篇文章就可以知道第三个问题了. 关于动态调用动态 ...

  9. 配置数据源的三种方式和sql心跳的配置

    三种方式配置数据源连接池: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  10. QQ音乐flac音乐转MP6格式怎样实现

    很多时候我们所下载的音乐格式都不是MP3格式的,用起来都是有局限性的,因为很多播放器都是支持MP3格式的.很多时候为了方便使用,我们就需要将不同的音乐格式转换为MP3格式的.如flac音乐转MP3的问 ...