题目要求

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. elk问题,求教各位大虾!

    [filebeat --> kafka --> logstash-->MongoDB|磁盘]架构进行日志收集 但是当logstash写入MongoDB有延迟,然后正常之后,会导致lo ...

  2. java中的数据加密4 数字签名

    数字签名 它是确定交换消息的通信方身份的第一个级别.A通过使用公钥加密数据后发给B,B利用私钥解密就得到了需要的数据,问题来了,由于都是使用公钥加密,那么如何检验是A发过来的消息呢?上面也提到了一点, ...

  3. Java知多少(67)面向字符的输入流

    字符流是针对字符数据的特点进行过优化的,因而提供一些面向字符的有用特性,字符流的源或目标通常是文本文件. Reader和Writer是java.io包中所有字符流的父类.由于它们都是抽象类,所以应使用 ...

  4. Android qualcomm WCNSS_qcom_cfg.ini 参数介绍

    本文介绍WCNSS_qcom_cfg.ini中常用参数的作用. wifi 日志等级 vosTraceEnableBAP=255 vosTraceEnableTL=255 vosTraceEnableW ...

  5. json 报错'xxx is not JSON serializable'的处理方法

    场景: 报错: 原因: json不能对np.int64或者np.float64等类型进行序列化,可以通过自定义serializer或者直接类型转换来解决. 解决方法: 显式的把 date 转换成 in ...

  6. ubuntu下mysql远程连接和访问慢的解决方法

    原本连接很快的mysql服务器,连接速度奇慢.以前几十毫秒的连接现在完成一次要近5秒钟,在排除了网络问题后,只有从mysql下手.原来每次访问db,mysql就会试图去解析来访问的机器的domain ...

  7. react 生命周期钩子里不要写逻辑,否则不生效

    react 生命周期钩子里不要写逻辑,否则不生效,要把逻辑写在函数里,然后在钩子里调用函数,否则会出现问题.

  8. Oracle relink 重新编译

    如此而已! export ORACLE_HOME=/opt/oracle/11.2 export LD_LIBRARY_PATH=/lib:/lib64:$ORACLE_HOME/lib:$ORACL ...

  9. iOS开发-- 开发中遇到的问题汇总

    1. CUICatalog: Invalid asset name supplied: 今天写了加载图片,默认图片写的是[UIImage imageNamed:@""],之后就报下 ...

  10. Android编译环境——ubuntu12.04上android2.3.4编译错误以及解决

    Android编译环境——ubuntu12.04上android2.3.4编译错误以及解决 分类: android应用开发2013-08-21 09:20 4222人阅读 评论(3) 收藏 举报 li ...