Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.
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. Note that this rule does not apply to 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. Note that this rule does not apply to domain names.
It is possible to use both of these rules at the same time.
Given an array of strings emails where we send one email to each emails[i], return the number of different addresses that actually receive mails.
Function Signature
def num_unique_emails(emails: list[str]) -> int:
Rules
-
The local name is the part before the single
'@'
; the domain name is the part after it.
-
In the local name, drop the first
'+'
and everything after it, then drop every
'.'
.
-
The domain name is kept exactly as written, dots included.
-
Return how many distinct addresses remain after these rules are applied to every entry.
Constraints
-
1 <= len(emails) <= 100
-
1 <= len(emails[i]) <= 100
-
emails[i]
consists of lowercase English letters,
'+'
,
'.'
and
'@'
.
-
Each
emails[i]
contains exactly one
'@'
character.
-
All local and domain names are non-empty.
-
Local names do not start with a
'+'
character.
-
Domain names end with the
".com"
suffix.
Examples
Input: emails = ["test.email+alex@example.com","test.e.mail+bob.cathy@example.com","testemail+david@ex.ample.com"]
Output: 2
The first two emails are sent to testemail@example.com. The third is sent to testemail@ex.ample.com, because dots in the domain are kept, so 2 different addresses receive mail.
Input: emails = ["a@example.com","b@example.com","c@example.com"]
Output: 3
All three emails have different local names and the same domain, so 3 different addresses receive mail.
Input: emails = ["m.a.x+one@site.com","max+two+three@site.com","max@site.com"]
Output: 1
The first local name loses +one and its dots, giving max. The second is cut at its first plus, so +two+three is dropped and it also gives max. All three reach max@site.com.