Unique Email Addresses
Given a list of email addresses, you need to count how many unique email addresses are actually being used. Each email address consists of a local name and a domain name, separated by the '@' symbol. A couple of special rules apply to the local name:
- Periods ('.') are ignored. For example, 'john.doe@gmail.com' and 'johndoe@gmail.com' are considered the same email.
- Plus sign ('+') cuts off everything after it in the local name. For instance, 'john+anything@gmail.com' will be treated as 'john@gmail.com'.
Task: Return the number of unique email addresses in the given list.
[ "test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com" ]
Explanation. The first two emails are normalized to 'testemail@leetcode.com', and the third one remains 'testemail@lee.tcode.com'. Thus, there are two unique email addresses.
[ "a@leetcode.com", "b@leetcode.com", "c@leetcode.com" ]
Explanation. All emails are unique.
[ "abc+def@leetcode.com", "abc@leetcode.com", "abc+xyz@leetcode.com" ]
Explanation. All these emails normalize to 'abc@leetcode.com'.
[ "xyz@leetcode.com" ]
Explanation. Only one email, so it's obviously unique.
Follow-up: Can you optimize your solution to handle large lists of email addresses efficiently?
The input list will contain at least 1 and at most 100 email addresses. Each email address is a non-empty string and valid according to RFC specs, except that for simplicity, we consider only the rules mentioned above.
- Views
- 2