【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, andleetcode.com
is 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.com
will 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 <= 100
1 <= 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)
最新文章
- HashMap实现缓存
- mysql导入大文件sql
- HTML5 LocalStorage 本地存储,刷新值还在
- c++作用域运算符---7
- C#支持文件拖拽
- nginx error_page 404 用 php header 无法跳转
- C++ sizeof总结
- ORACLE OCP认证
- sriov查看pf-vf对应关系
- iOS 真机调试(最具体的步骤来解决历史,hmt精心打造)
- GreenDao
- 使用ADO.NET查询和访问数据库
- 070 DStream中的transform和foreachRDD函数
- Deep Dream 模型
- GMap.NET实现电子围栏功能(WPF版)
- python 提取linux的硬件信息
- [转]mmap和madvise的使用
- js常见input校验
- 【Ansible 文档】【译文】模式
- web前端工程师在移动互联网时代里的地位问题 为啥C/S系统在PC端没有流行起来,却在移动互联网下流行了起来 为啥移动端的浏览器在很多应用里都是靠边站,人们更加倾向于先麻烦自己一下,下载安装个客户端APP
热门文章
- Install packages failed: Installing packages: error occurred. ------简单的问题常常会被忽略
- boost IOStreams
- boost array
- java-设计原则
- MySqL rownum 序号 类似于 oracle的rownum
- Sqlachemy的警告SAWarning: The IN-predicate on ";sns_object.BIZ_ID"; was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.
- git分支回退以及目录回退
- Tarjan 总结
- codeforces 584E Anton and Ira [想法题]
- 20150721&mdash;HTML的定位 JS (转)