题目要求

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. hdoj:2037

    #include <iostream> using namespace std; struct Time { int start; int end; }; Time times[]; ]; ...

  2. Qt动态库静态库的创建、使用、多级库依赖、动态库改成静态库等详细说明

    本文描述的是windows系统下,通过qtcreator在pro文件中添加动态库与静态库的方法: 1.添加动态库(直接添加动态库文件.dll,非子项目) 通过qtcreator创建动态库的方法就不在此 ...

  3. 飞鱼48小时游戏创作嘉年华_厦门Pitch Time总结与收获

    一.48小时游戏开发前期准备 1,策划 明确美术队友和程序队友的水平,提需求的过程中尝试做减法,在保留核心玩法的基础上,看队友水平和时间判断是否添加需求. 策划是整个游戏团队的灵魂,也是开发的上限所在 ...

  4. mysql语法 -- concat函数

    mysql CONCAT(str1,str2,…)                        返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL.或许有一个或多个参 ...

  5. 占位 Bootstrap

    中文网  http://www.bootcss.com/

  6. adb shell dumpsys 命令

    Android开发中,常常可以用adb shell dumpsys这条命令来dump出系统运行时的状态信息,例如可以这样来察看某个应用的内存使用信息 adb shell dumpsys meminfo ...

  7. 通过mysql写入php一句话木马

    利用mysql写入一句话木马 前提: root权限,知道了服务器的web的绝对路径 select "<?php @eval($_POST['pass']);?>" IN ...

  8. localhost兼容js不能用

  9. 仿迅雷播放器教程 -- C++ windows界面库对比(11)

    从上一篇文章中可以看出,C++的界面方向还很弱,没有任何一个界面库可以一统天下,所以才造成了界面库百家争鸣的情况. 从时间上看: 1.出来最早的是QT,1991年就有了. 2.VC++ 虽然1992年 ...

  10. [原]openstack-kilo--issue(二十二) 虚拟机的vnc console图像调用错误

    [问题点] 在打开node compute 上vm的vnc console窗口时候发现vm1-compute1调用的是vm1-controller上的vnc图像 =================== ...