Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign. For example in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.
Besides lowercase letters, email addresses may contain '.'s or '+'s in the local name. 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, "a.l.i.c.e@leetcode.com" and "alice@leetcode.com" forward to the same email address. (Note that this rule does not apply for domain names.)
Additionally, a plus symbol ('+') in the local name means that all detail after that specific plus must be ignored (this does not apply to the domain name). For example, "alice+spamblock@leetcode.com" directs emails to "alice@leetcode.com".
Given an array of email addresses, return the number of unique emails actually sent to different addresses.
[ [ "alice@leetcode.com" ] ]
Explanation. There is only one unique email address.
[ [ "a.l.i.c.e@leetcode.com", "alice@leetcode.com" ] ]
Explanation. Both direct to 'alice@leetcode.com' due to rules about '.' symbol in local name.
[ [ "alice@leetcode.com", "alice+spamblock@leetcode.com", "a.l.i.ce@leetcode.com" ] ]
Explanation. All these variations direct to 'alice@leetcode.com'.
[ [ "bob+extra@leetcode.com", "bob@leetcode.com" ] ]
Explanation. All emails for 'bob' direct to 'bob@leetcode.com'.
Follow-up: How would you handle email addresses with unusual domain names or symbols?
The array of email addresses will contain between 1 and 100 entries, and each entry is a valid email.
- Views
- 2