Unique Email Addresses
Every valid email consists of a local name and a domain name, separated by the '@' symbol. 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. For example, 'alice.z@example.com' and 'alicez@example.com' redirect to the same email address.
- 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. For example, 'alice+spam@example.com' goes to 'alice@example.com'.
Given an array of email addresses, return the number of unique email addresses that actually receive mails.
[ "test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com" ]
Explanation. The emails 'test.email+alex@leetcode.com' and 'test.e.mail+bob.cathy@leetcode.com' are delivered to the same email 'testemail@leetcode.com'. The last one is delivered to 'testemail@lee.tcode.com'. So two different emails are used.
[ "a@leetcode.com", "b@leetcode.com" ]
Explanation. All emails are unique.
[ "dot.email+merge@leetcode.com", "d.o.t.email+merge@leetcode.com", "do.t.e.mail+merge@leetcode.com" ]
Explanation. All emails are delivered to 'dotemail@leetcode.com'.
Follow-up: Can you solve the problem in linear time and space complexity?
Each email address contains one '@' character. All local and domain names are non-empty. The emails will consist only of lowercase letters, '+' or '.'.
- Views
- 3