-
Notifications
You must be signed in to change notification settings - Fork 43
/
unique-email-addresses.py
57 lines (52 loc) · 1.48 KB
/
unique-email-addresses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# V0
# V1
# https://blog.csdn.net/fuxuemingzhu/article/details/83478570
class Solution(object):
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
eset = set()
for email in emails:
simper = self.simpifyEmail(email)
eset.add(simper)
return len(eset)
def simpifyEmail(self, email):
local, domain = email.split("@")
local = local.replace('.', '')
plus_i = local.find('+')
if plus_i != -1:
local = local[:plus_i]
return local + "@" + domain
# V1'
# https://blog.csdn.net/fuxuemingzhu/article/details/83478570
class Solution:
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
res = set()
for email in emails:
name, domain = email.split("@")
name = name.split("+")[0].replace(".", "")
res.add(name + "@" + domain)
return len(res)
# V2
# Time: O(n * l)
# Space: O(n * l)
class Solution(object):
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
def convert(email):
name, domain = email.split('@')
name = name[:name.index('+')]
return "".join(["".join(name.split(".")), '@', domain])
lookup = set()
for email in emails:
lookup.add(convert(email))
return len(lookup)