题目要求

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. cad巧用插件自定义填充图形

    很多同志如果遇到奇葩的填充图案,怎么办,找不到合适的,自己辛苦画了一遍,想把它作为自己的自定义的图案,怎么办呢. 今天老王给你您介绍个好用的插件. 首先在命令行输入命令  ap 弹出加载对话框 打开窗 ...

  2. 【iCore4 双核心板_FPGA】例程九:锁相环实验——锁相环使用

    实验现象: 利用Quartus内部组件生成锁相环,用SignalTap II进行校验. 核心代码: module pll( input clk_25m, output clk_100m, output ...

  3. CEO退休

    早上刚来公司就收到群发邮件,说CEO退休了,在公司服务了22年.以后还是会part time做vice chairman.其实在公司也没打过几次照面...就知道是个和善的老人,祝他退休生活幸福! 我的 ...

  4. hdoj:2031

    #include <iostream> #include <string> using namespace std; int main() { int N,R; string ...

  5. 【转】VMware Tools installation cannot be started manually while Easy Install is in progress.

    我HOST 是WIN7也遇到了这样的问题 我这样做的:进入系统以后在你VM的下面会有几个图标:关于1,CD DVD 2,disk 3,floppy 4,网络连接... 选择floppy--settin ...

  6. 生产环境使用nginx做负载均衡配置的五种策略

    nginx的upstream目前支持5种方式的分配1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. 2.weight指定轮询几率,weight和访 ...

  7. [原]VS2012编译GLEW 1.11

    1.到http://glew.sourceforge.net/下载源代码 2.使用vs2012打开build下vc6的glew.dsw ,自动生成2012工程(一路点确定)特别注意:不要使用build ...

  8. linux(centos) 添加系统环境变量

    系统环境变量,其实就就是一个添加至系统环境中的路径变量. 编译php的扩展时经常会在扩展包源码目录里执行phpize,每次执行的时候都要敲入一大堆目录,诸如:/usr/local/php/bin/ph ...

  9. sklearn参数优化方法

    学习器模型中一般有两个参数:一类参数可以从数据中学习估计得到,还有一类参数无法从数据中估计,只能靠人的经验进行指定,后一类参数就叫超参数 比如,支持向量机里的C,Kernel,gama,朴素贝叶斯里的 ...

  10. [原]Jenkins(九)---jenkins分别发布多个项目到多个远程主机

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...