Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contribute solution problem 0929 and add me to file README.md
- Loading branch information
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# [929. Unique Email Addresses][title] | ||
|
||
## Description | ||
|
||
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:** | ||
|
||
``` | ||
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 | ||
``` | ||
|
||
## NOTES | ||
|
||
1 <= emails[i].length <= 100 | ||
1 <= emails.length <= 100 | ||
Each emails[i] contains exactly one '@' character. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package Solution | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
func numUniqueEmails(emails []string) int { | ||
emailSet := map[string]bool{} | ||
for _, email := range emails { | ||
parts := strings.Split(email, "@") | ||
localName := strings.Replace(strings.Split(parts[0], "+")[0], ".", "", -1) | ||
emailSet[localName+"@"+parts[1]] = true | ||
} | ||
return len(emailSet) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package Solution | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSolution(t *testing.T) { | ||
listTest := []string{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"} | ||
got := numUniqueEmails(listTest) | ||
want := 2 | ||
if got != want { | ||
t.Errorf("want '%d' but got '%d'", want, got) | ||
} | ||
} |