# Leetcode - Unique Email Addresses

violet posted @ Jul 15, 2020 02:33:33 AM in 算法 with tags Algorithm Golang string , 548 阅读

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, these emails may contain `'.'`s or `'+'`s.

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@leetcode.com"` and `"alicez@leetcode.com"` forward to the same email address.  (Note that this rule does not apply for 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, for example `m.y+name@email.com` will be forwarded to `my@email.com`.  (Again, this rule does not apply for domain names.)

It is possible to use both of these rules at the same time.

Given a list of `emails`, we send one email to each address in the list.  How many different addresses actually receive mails?

Example 1:

```Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
Output: 2
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails
```

```func numUniqueEmails(emails []string) int {
hash := map[string]int{}
for _, email := range emails {
strs := strings.Split(email, "@")
user := strings.Split(strs[0], "+")[0]
domain := strs[1]
}
return len(hash)
}```
Jharkhand Matric Imp 说:
Aug 24, 2022 12:54:36 PM

JAC 10th Question Paper 2023 Download – Jharkhand Matric Important Question Paper 2023 PDF, The State of Jharkhand came into existence on the 15th of November,2000. An Act to establish the Jharkhand Academic Council was enacted by the Jharkhand State Legislature and assented to by the Governor of the State on 26-12-2003, Jharkhand Matric Important Question Paper 2023 PDF/a> which was known as Jharkhand Academic Council Act 02.7.2003.

How to Recharge FAST 说:
Nov 11, 2022 03:10:17 PM

India’s digital market has influenced different industries, such as the transport sector and the banking system. These ranks India among the top best and advanced countries in the world. The digital transformation helps transact cash online without physically handling money. How to Recharge FASTag Using PhonePe Today India’s National Highway Authority benefits from online payment services such as FASTag. Drivers can pay for their toll without stopping at every toll plaza.

Emma 说:
Nov 16, 2022 10:56:07 PM

Leetcode's "Unique Email Addresses" problem is a great example what causes gout of how to use a HashSet to keep track of unique elements. The key here is to normalize the email addresses by removing the . and + characters. This way, we can be sure that all duplicate email addresses will be correctly identified.

Dec 19, 2022 05:35:27 PM