Skip to content

Commit 80fd026

Browse files
committed
Add solution #929
1 parent ad28f3f commit 80fd026

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 929. Unique Email Addresses
3+
* https://leetcode.com/problems/unique-email-addresses/
4+
* Difficulty: Easy
5+
*
6+
* Every email consists of a local name and a domain name, separated by the @ sign.
7+
*
8+
* For example, in [email protected], alice is the local name, and leetcode.com is the domain name.
9+
*
10+
* Besides lowercase letters, these emails may contain '.'s or '+'s.
11+
*
12+
* If you add periods ('.') between some characters in the local name part of an email address, mail
13+
* sent there will be forwarded to the same address without dots in the local name.
14+
* For example, "[email protected]" and "[email protected]" forward to the same email address.
15+
* (Note that this rule does not apply for domain names.)
16+
*
17+
* If you add a plus ('+') in the local name, everything after the first plus sign will be ignored.
18+
* This allows certain emails to be filtered, for example [email protected] will be forwarded to
19+
* [email protected]. (Again, this rule does not apply for domain names.)
20+
*
21+
* It is possible to use both of these rules at the same time.
22+
*
23+
* Given a list of emails, we send one email to each address in the list.
24+
* How many different addresses actually receive mails?
25+
*/
26+
27+
/**
28+
* @param {string[]} emails
29+
* @return {number}
30+
*/
31+
var numUniqueEmails = function(emails) {
32+
return new Set(emails.map(e => e.replace(/\.(?=[\w\.+]+@)|\+[\w.+]+(?=@)/g, ''))).size;
33+
};

0 commit comments

Comments
 (0)