[
counter
hash table
parser
]
Leetcode 0929. Unique Email Addresses
Problem statement
https://leetcode.com/problems/unique-email-addresses/
Solution
We need to carefully traverse our emails, replace all dots and also check +
case.
Complexity
It is O(m)
for time and space, where m
is the total length of all emails.
Code
class Solution:
def numUniqueEmails(self, emails):
d = Counter()
for mail in emails:
local, domain = mail.split("@")
local = local.replace(".", "")
if "+" in local: local = local[:local.index("+")]
d[local + "@" + domain] += 1
return len(d)