【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 ...
随机推荐
- BiNGO的GO分析
GO富集分析对老师们来说想必都不陌生,几乎在任何项目中都会出现.今天就给大家介绍一款简单易学又好用的富集分析小软件---BiNGO.它是Cytoscape软件中很出色的一个插件.它提供的结果中除了文本 ...
- git 如何删除远程仓库的错误提交
前言 最近一个版本发生产环境以后,忘了把分支切回开发分支,直接在release分支上开发新功能提交了....于是就需要去删除远程仓库的错误提交. git命令行实现 1.强制返回上次的版本(~1回退到上 ...
- js 最短代码生成随机数(字符串、id)
以生成8位字符串为例 Math.random().toString(36).substr(-8)
- springboot2集成redis5报错:io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: DENIED Redis is running in protected
报错信息如下: Caused by: io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: DENIED ...
- linux网络接口,struct ifreq struct ifconf结构
网络相关的ioctl请求的request参数及arg地址必须指向的数据类型如下表所示: 接口 SIOCGIFCONF SIOCSIFADDR SIOCGIFADDR SIOCSIFBRDADDR SI ...
- BZOJ 3772: 精神污染(dfs序+主席树)
传送门 解题思路 比较神仙的一道题.首先计算答案时可以每条路径所包含的路径数,对于\(x,y\)这条路径,可以在\(x\)这处开个\(vector\)存\(y\),然后计算时只需要算这个路径上每个点的 ...
- 一片关于Bootstarp4的文章
一.Bootstarp Bootstrap 是全球最受欢迎的前端组件库,用于开发响应式布局.移动设备优先的 WEB 项目.可以让你快速的排版,不用在写那些繁杂的样式.Bootstrap是开源免费的,设 ...
- Nuget-Doc:Nuget 简介
ylbtech-Nuget-Doc:Nuget 简介 1.返回顶部 1. NuGet 简介 2019/05/24 适用于任何现代开发平台的基本工具可充当一种机制,通过这种机制,开发人员可以创建.共享和 ...
- JS-for..of
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/for...of 刚刚上网上看到<V8 ...
- configure error C compiler cannot create executables错误解决
我们在编译软件的时候,是不是经常遇到下面的错误信息呢? checking build system type... i686-pc-linux-gnuchecking host system ty ...