【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 ...
随机推荐
- Linux中Hard link和Symbol link的区别
Hard link Hard link不能指向不在同一磁盘的文件 Hard link不能指向目录 Hard link与源文件几乎没有区别.只能通过ls -li看出link关系.另外,删除源文件后,Ha ...
- kill命令的几种信号
1 HUP: hangup 2 INIT: 相当于 Ctrl + c 9 KILL 15 TERM: Terminate (kill 的默认信号) 18 CONT: Continue (从STOP信号 ...
- yield关键字详解与三种用法
本篇文章比较硬核, 适合有一定Python基础的读者阅读, 如果您对Python还不甚了解可以先关注我哦, 我会持续更新Python技术文章 yield详解 yield与return相同每次调用都会返 ...
- 【Tomcat】Tomcat系统架构
一.Tomcat顶层架构 先上一张Tomcat的顶层结构图(图A),如下: Tomcat中最顶层的容器是Server,代表着整个服务器,从上图中可以看出,一个Server可以包含至少一个Service ...
- php strnatcasecmp()函数 语法
php strnatcasecmp()函数 语法 作用:使用"自然"算法来比较两个字符串(不区分大小写):直线电机优势 语法:strnatcasecmp(string1,strin ...
- 【SPOJ8222】Substrings (后缀自动机)
题意: 给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值. 求F(1)..F(Length(S)) Length(S) <= 250000 思路:板子中st[x]定义为r ...
- 转载:IDEA lombok插件的安装和使用
转载自:https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html lombok插件的安装 1 首先我们需要安装IntelliJ ...
- VB.NET导出Excel 轻松实现Excel的服务器与客户端交换 服务器不安装Office
说来VB.Net这个也是之前的一个项目中用到的.今天拿来总结下用途,项目需求,不让在服务器安装Office办公软件.这个也是煞费了一顿. 主要的思路就是 在导出的时候,利用DataTable做中间变量 ...
- Window随笔 - Windows Server 2012 評估版與延長使用期限【转载】
Windows Server 2012 評估版與延長使用期限 下載與安裝 至 微軟的評估中心 下載 Windows Server 2012 SP1 180 天軟體試用版 (Windows Server ...
- USACO 5.3 章节
相关讲解可在USACO上看原文,也可以搜索nocow找到翻译的! (nocow上有些微翻译是有问题的,如果想看nocow翻译的建议也对着英文看) 以下记录以下 自己之前未掌握的一些要点,以及按自己的括 ...