【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,aliceis the local name, andleetcode.comis the domain name.Besides lowercase letters, these emails may contain
'.'s or'+'s.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 examplem.y+name@email.comwill be forwarded tomy@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?Example 1:
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 mailsNote:
1 <= emails[i].length <= 1001 <= emails.length <= 100- Each
emails[i]contains exactly one'@'character.
解题思路:82%的通过率足以证明这题有多简单。把local name的 '.'替换成'',并且截断第一个'+'后面的内容即可。
代码如下:
class Solution(object):
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
dic = {}
for i in emails:
e = i.split('@')
e[0] = e[0].replace('.','')
if '+' in e[0]:
e[0] = e[0][:e[0].index('+')]
if e[0] + '@' + e[1] not in dic:
dic[e[0] + '@' + e[1]] = 1
#print dic
return len(dic)
【leetcode】929. Unique Email Addresses的更多相关文章
- 【LeetCode】929. Unique Email Addresses 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 set + 字符串操作 参考资料 日期 题目地址:h ...
- 【Leetcode_easy】929. Unique Email Addresses
problem 929. Unique Email Addresses solution: class Solution { public: int numUniqueEmails(vector< ...
- 929. Unique Email Addresses
929. Unique Email Addresses Easy 22766FavoriteShare Every email consists of a local name and a domai ...
- 【LeetCode】95. Unique Binary Search Trees II 解题报告(Python)
[LeetCode]95. Unique Binary Search Trees II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzh ...
- [leetcode] 929. Unique Email Addresses (easy)
统计有几种邮箱地址. 邮箱名类型:local@domain 规则:1. local中出现"."的,忽略. a.bc=abc 2. local中出现"+"的,+以 ...
- [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
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, i ...
随机推荐
- java 节点流(字符流,字节流)和包装流(缓冲流,转换流)
结点流:直接对File类进行操作的文件流 package stream; import java.io.File; import java.io.FileNotFoundException; impo ...
- HTML 3-列表、表单、语义化
有序列表.无序列表.自定义列表在语义上的区别 1.有序列表ol>li:列表有顺序编号(默认列表前加1.,2.,3.,...编号),适用于有逻辑顺序的排列项目,而且次序不能乱.2.无序列表ul&g ...
- 小程序UI自动化(一):appium小程序自动化尝试
appium 进行 小程序自动化尝试: 由于工作中进行app自动化用的是appium,故首先尝试用appium进行小程序自动化,以美团小程序为例(python脚本实现) 一.配置基础信息 启动微信ap ...
- iText例子
参考:http://itextpdf.com/book/examples.php daniel@daniel-mint ~/latex/linux/itext/daniel $ cat HelloWo ...
- java多线程学习笔记(八)
本节开始线程间通信: 使用wait/notify实现线程间通信 生产者/消费者模式的实现 方法join的使用 ThreadLocal类的使用 可以通过使用 sleep() 结合 while(true) ...
- 详解linux io flush
通过本文你会清楚知道 fsync().fdatasync().sync().O_DIRECT.O_SYNC.REQ_PREFLUSH.REQ_FUA的区别和作用. fsync() fdatasync( ...
- Java组合实体模式~
组合实体模式用于EJB持久化机制. 组合实体是表示对象图的EJB实体bean. 当组合实体更新时,内部依赖对象bean将自动更新为由EJB实体bean管理. 以下是组合实体Bean的参与者. 组合实体 ...
- Java并发AtomicIntegerArray类
java.util.concurrent.atomic.AtomicIntegerArray类提供了可以以原子方式读取和写入的底层int数组的操作,还包含高级原子操作. AtomicIntegerAr ...
- HDU3449_Consumer
这个是一个背包的变形题,很值得仔细体味 大致题意: 这个比普通背包多一个限制:再选每一类物品之前必须要先购买一个篮子来装,篮子有一定的价格,其他就和背包是一样的了 思路: 为了能够体现篮子的价值,我们 ...
- CSS深入理解line-height
1.line-height高度基于基线 2. 3.p元素的高度由行高决定的 4. 5.