-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
34 lines (30 loc) · 1.04 KB
/
solution.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
from typing import List
class Solution:
def numUniqueEmails(self, emails: List[str]) -> int:
# solution 1:
# unique = set()
# for email in emails:
# local, domain = email.split("@")
# local = local.split("+")[0]
# local = local.replace(".", "")
# unique.add((local, domain))
# return len(unique)
# solution 2:
unique = set()
for email in emails:
# local
index, local = 0, ""
while email[index] not in ["@", "+"]:
if email[index] != ".":
local += email[index]
index += 1
# domain
while email[index] != "@":
index += 1
domain = email[index+1:]
unique.add((local, domain))
return len(unique)
if __name__ == '__main__':
emails = ["[email protected]",
print(Solution().numUniqueEmails(emails))