Skip to content

Commit 7c0bffb

Browse files
authored
Merge pull request 6boris#50 from hiepndd/develop
Contribute solution problem 0929 and add me to file README.md
2 parents ccc608b + ac3b56e commit 7c0bffb

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 📝 awesome-golang-leetcode
22

3-
43
LeetCode of algorithms with golang solution(updating:smiley:).
54

65
<p align="center">
@@ -29,16 +28,15 @@ LeetCode of algorithms with golang solution(updating:smiley:).
2928
</a>
3029
</p>
3130

32-
33-
3431
## Contributors
3532

3633
Thanks goes to these wonderful people ([emoji key](https://github.com/all-contributors/all-contributors#emoji-key)):
3734

3835
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
3936
<!-- prettier-ignore -->
40-
| [<img src="https://avatars0.githubusercontent.com/u/26195433?v=4" width="100px;" alt="Kyle Liu "/><br /><sub><b>Kyle Liu </b></sub>](https://kyle.link)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Code") [📝](#blog-kylesliu "Blogposts") [🎨](#design-kylesliu "Design") [📖](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/34671440?v=4" width="100px;" alt="hapiman2"/><br /><sub><b>hapiman2</b></sub>](https://github.com/hapiman2)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman2 "Code") | [<img src="https://avatars0.githubusercontent.com/u/7567048?v=4" width="100px;" alt="hapiman"/><br /><sub><b>hapiman</b></sub>](https://github.com/hapiman)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman "Code") | [<img src="https://avatars2.githubusercontent.com/u/26058740?v=4" width="100px;" alt="sihg yu"/><br /><sub><b>sihg yu</b></sub>](https://github.com/sihgyu)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=sihgyu "Code") | [<img src="https://avatars3.githubusercontent.com/u/38197795?v=4" width="100px;" alt="plusweiwei"/><br /><sub><b>plusweiwei</b></sub>](https://github.com/plusweiwei)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=plusweiwei "Code") | [<img src="https://avatars0.githubusercontent.com/u/6274967?v=4" width="100px;" alt="Sandy"/><br /><sub><b>Sandy</b></sub>](https://openset.github.com)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=openset "Code") |
37+
| [<img src="https://avatars0.githubusercontent.com/u/26195433?v=4" width="100px;" alt="Kyle Liu "/><br /><sub><b>Kyle Liu </b></sub>](https://kyle.link)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Code") [📝](#blog-kylesliu "Blogposts") [🎨](#design-kylesliu "Design") [📖](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/34671440?v=4" width="100px;" alt="hapiman2"/><br /><sub><b>hapiman2</b></sub>](https://github.com/hapiman2)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman2 "Code") | [<img src="https://avatars0.githubusercontent.com/u/7567048?v=4" width="100px;" alt="hapiman"/><br /><sub><b>hapiman</b></sub>](https://github.com/hapiman)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman "Code") | [<img src="https://avatars2.githubusercontent.com/u/26058740?v=4" width="100px;" alt="sihg yu"/><br /><sub><b>sihg yu</b></sub>](https://github.com/sihgyu)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=sihgyu "Code") | [<img src="https://avatars3.githubusercontent.com/u/38197795?v=4" width="100px;" alt="plusweiwei"/><br /><sub><b>plusweiwei</b></sub>](https://github.com/plusweiwei)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=plusweiwei "Code") | [<img src="https://avatars0.githubusercontent.com/u/6274967?v=4" width="100px;" alt="Sandy"/><br /><sub><b>Sandy</b></sub>](https://openset.github.com)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=openset "Code") | [<img src="https://avatars0.githubusercontent.com/hiepndd" width="100px;" alt="hiepndd"/><br /><sub><b>hiepndd</b></sub>](https://github.com/hiepndd)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hiepndd "Code") |
4138
| :---: | :---: | :---: | :---: | :---: | :---: |
39+
4240
<!-- ALL-CONTRIBUTORS-LIST:END -->
4341

44-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
42+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [929. Unique Email Addresses][title]
2+
3+
## Description
4+
5+
Every email consists of a local name and a domain name, separated by the @ sign.
6+
7+
For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.
8+
9+
Besides lowercase letters, these emails may contain '.'s or '+'s.
10+
11+
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.)
12+
13+
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.)
14+
15+
It is possible to use both of these rules at the same time.
16+
17+
Given a list of emails, we send one email to each address in the list. How many different addresses actually receive mails?
18+
19+
**Example:**
20+
21+
```
22+
Input: ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
23+
Output: 2
24+
Explanation: "testemail@leetcode.com" and "testemail@lee.tcode.com" actually receive mails
25+
26+
```
27+
28+
## NOTES
29+
30+
1 <= emails[i].length <= 100
31+
1 <= emails.length <= 100
32+
Each emails[i] contains exactly one '@' character.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package Solution
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func numUniqueEmails(emails []string) int {
8+
emailSet := map[string]bool{}
9+
for _, email := range emails {
10+
parts := strings.Split(email, "@")
11+
localName := strings.Replace(strings.Split(parts[0], "+")[0], ".", "", -1)
12+
emailSet[localName+"@"+parts[1]] = true
13+
}
14+
return len(emailSet)
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package Solution
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestSolution(t *testing.T) {
8+
listTest := []string{"test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"}
9+
got := numUniqueEmails(listTest)
10+
want := 2
11+
if got != want {
12+
t.Errorf("want '%d' but got '%d'", want, got)
13+
}
14+
}

0 commit comments

Comments
 (0)