LeetCode 929 Unique Email Addresses 解题报告
题目要求
Every email consists of a local name and a domain name, separated by the @ sign.
For example, in alice@leetcode.com, alice 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 <= 1001 <= 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 解题报告的更多相关文章
- 【LeetCode】929. Unique Email Addresses 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- LeetCode 929.Unique Email Addresses
Description Every email consists of a local name and a domain name, separated by the @ sign. For exa ...
- [LeetCode] 929. Unique Email Addresses 唯一的电邮地址
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- [LeetCode] 929. Unique Email Addresses 独特的邮件地址
Every email consists of a local name and a domain name, separated by the @ sign. For example, in ali ...
- LeetCode 929. Unique Email Addresses (独特的电子邮件地址)
题目标签:String 题目说明 有两个规则针对于 local name. 所以先把local name 和 domain name 分开. 两个规则是: rule 1:'.' 会被去除. (利用re ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- 【leetcode】929. Unique Email Addresses
题目如下: Every email consists of a local name and a domain name, separated by the @ sign. For example, ...
随机推荐
- 【iCore4 双核心板_FPGA】例程十三:基于SPI的ARM与FPGA通信实验
实验现象: 1.先烧写ARM程序,然后烧写FPGA程序. 2.打开串口精灵,通过串口精灵给ARM发送数据从而给FPGA发送数据 ,会接收到字符HELLO. 3.通过串口精灵发送命令可以控制ARM·LE ...
- Java多线程:SimpleDateFormat
一.SimpleDateFormat的线程安全问题 为什么SimpleDateFormat是线程不安全的? 下面通过一个案例代码来说明 public class DateUtilTest { publ ...
- 《objective-c基础教程》学习笔记(六)—— 复合方法
今天我们要讲的复合,当然不是小情侣吵着分手,然后又在一起的复合. 复合遵循一个合成复用原则,又称为组合或者聚合复用原则.该原则的内容是:尽量使用对象组合,而不是继承来达到复用的目的.用聚合可以使系统更 ...
- Java -- POI -- 随笔汇总
1. 判断指定的单元格是否是合并单元格 /** * 功能:判断指定的单元格是否是合并单元格 * 原理:excel中的合并单元格其实就是首单元格,只不过该单元格增加了 rowspan和colspan两个 ...
- Excel如何实现两个工作表数据的对比
https://jingyan.baidu.com/article/63f236281f17650208ab3d97.html Sub 数据对比() Dim i As Integer Dim j As ...
- Android 监听键盘弹出和收起.
entends:http://stackoverflow.com/questions/36837066/how-to-validate-virtual-keyboard-visibility 监听键盘 ...
- 如何实现@ResponseBody,把Json字符串转换为指定类型
1.问题 spring 是如何把 http中的body,转换为指定类的,里面的难点其实在于泛型的处理. 2.Spring的处理 2.1 HandlerMethod 这个类Spring对Method的封 ...
- Flask web开发之路七
今天写SQLAlchemy数据库 首先介绍ORM的概念: ORM,Object类,Relationship:关系,Mapping:映射,也就是模型关系映射 flask-sqlalchemy是一套ORM ...
- xshell连接Linux、ngix部署
Linux端安装sshd服务(openssh-server) 查看防火墙:ufw(Linux默认安装了) 再就是客户端了.. 平时在测试环境下的项目不能承载高并发,需要部署到web server上.w ...
- sql优化的方法
参考:https://blog.csdn.net/jie_liang/article/details/77340905 11.不要写一些没有意义的查询,如需要生成一个空表结构: select col1 ...