【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)
【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 ...
随机推荐
- Android Fastboot 与 Recovery 和刷机 千山万水迷了鹿
1. 首先来看下Android系统的分区: Android系统的分区.jpg Android分区解释.png 安卓系统一般把rom芯片分成7个区,如果再加上内置sd卡这个分区,就是8个: hb ...
- TypeError:NoneType object is not callable情况下的错误
只用在该视图函数下面加上return ‘值’
- 对于vue绑定的model值里边get和set的小动作
先看下例子: template里边内容: <el-form-item label="导航条类型"> <el-radio-group v-model="n ...
- 2018-2019-2 实验四 Android程序设计
实验要求 参考Android开发简易教程 完成云班课中的检查点,也可以先完成实验报告,直接提交.注意不能只有截图,要有知识点,原理,遇到的问题和解决过程等说明.实验报告中一个检查点要有多张截图. 发表 ...
- Windows-计划任务-自动备份数据库和文件
开始 -> 程序 -> 附件 -> 系统工具 -> 计划任务 .bat 文件如下: ::数据库+文件备份 @echo off ::日期时间 set yyyymmdd=%date ...
- 测开之路三十五:css引入
CSS是一种定义样式结构,如字体.颜色.位置等的语言,被用于描述网页上的信息格式化和现实的方式.CSS样式可以直接存储于HTML网页或者单独的样式单文件.无论哪一种方式,样式单包含将样式应用到指定类型 ...
- 首次使用Git将码云上的代码Clone至本地
使用Git将码云上的代码Clone至本地 1. 安装Git https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-G ...
- Netty 如何实现心跳机制与断线重连?
作者:sprinkle_liz www.jianshu.com/p/1a28e48edd92 心跳机制 何为心跳 所谓心跳, 即在 TCP 长连接中, 客户端和服务器之间定期发送的一种特殊的数据包, ...
- VMware中Centos7的静态ip设置
网络连接方式:桥接模式.修改后确定.启动centos7,root账户进行登录. 2.修改网卡配置文件 (1) 打开网卡配置文件 vim /etc/sysconfig/network-scripts/i ...
- 面相对象编程 扩充之封装、访问机制、 property
封装: 封装指的是可以将一堆属性和方法,封装到对象中 ps : 对象就好比一个 “袋子/容器”, 可以存放一堆属性和方法 ps : 存不是目的,目的是为了取,可以通过“对象” d的方式获取属性或方法 ...