题目如下:

Every email consists of a local name and a domain name, separated by the @ sign.

For example, in alice@leetcode.comalice is the local name, and leetcode.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 example m.y+name@email.com will be forwarded to my@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 mails

Note:

  • 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)

最新文章

  1. HashMap实现缓存
  2. mysql导入大文件sql
  3. HTML5 LocalStorage 本地存储,刷新值还在
  4. c++作用域运算符---7
  5. C#支持文件拖拽
  6. nginx error_page 404 用 php header 无法跳转
  7. C++ sizeof总结
  8. ORACLE OCP认证
  9. sriov查看pf-vf对应关系
  10. iOS 真机调试(最具体的步骤来解决历史,hmt精心打造)
  11. GreenDao
  12. 使用ADO.NET查询和访问数据库
  13. 070 DStream中的transform和foreachRDD函数
  14. Deep Dream 模型
  15. GMap.NET实现电子围栏功能(WPF版)
  16. python 提取linux的硬件信息
  17. [转]mmap和madvise的使用
  18. js常见input校验
  19. 【Ansible 文档】【译文】模式
  20. web前端工程师在移动互联网时代里的地位问题 为啥C/S系统在PC端没有流行起来,却在移动互联网下流行了起来 为啥移动端的浏览器在很多应用里都是靠边站,人们更加倾向于先麻烦自己一下,下载安装个客户端APP

热门文章

  1. Install packages failed: Installing packages: error occurred. ------简单的问题常常会被忽略
  2. boost IOStreams
  3. boost array
  4. java-设计原则
  5. MySqL rownum 序号 类似于 oracle的rownum
  6. Sqlachemy的警告SAWarning: The IN-predicate on &quot;sns_object.BIZ_ID&quot; was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.
  7. git分支回退以及目录回退
  8. Tarjan 总结
  9. codeforces 584E Anton and Ira [想法题]
  10. 20150721&mdash;HTML的定位 JS (转)