Skip to content

Commit 49f435e

Browse files
committed
feat: update solutions to lc problem: No.0929
No.0929.Unique Email Addresses
1 parent 37bf909 commit 49f435e

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

solution/0900-0999/0929.Unique Email Addresses/README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
<!-- 这里可写通用的实现逻辑 -->
6363

64+
**方法一:哈希表**
65+
6466
利用哈希表存放转换后的电子邮件,最后返回哈希表的 size 即可。
6567

6668
<!-- tabs:start -->
@@ -72,13 +74,12 @@
7274
```python
7375
class Solution:
7476
def numUniqueEmails(self, emails: List[str]) -> int:
75-
ans = 0
7677
s = set()
7778
for email in emails:
7879
local, domain = email.split('@')
7980
local = local.replace('.', '')
80-
if '+' in local:
81-
local = local[:local.find('+')]
81+
if (i := local.find('+')) != -1:
82+
local = local[:i]
8283
s.add(local + '@' + domain)
8384
return len(s)
8485
```
@@ -93,9 +94,8 @@ class Solution {
9394
Set<String> s = new HashSet<>();
9495
for (String email : emails) {
9596
String[] t = email.split("@");
96-
String local = t[0];
97+
String local = t[0].replace(".", "");
9798
String domain = t[1];
98-
local = local.replace(".", "");
9999
int i = local.indexOf('+');
100100
if (i != -1) {
101101
local = local.substring(0, i);
@@ -130,6 +130,22 @@ public:
130130
};
131131
```
132132
133+
### **Go**
134+
135+
```go
136+
func numUniqueEmails(emails []string) int {
137+
s := map[string]bool{}
138+
for _, email := range emails {
139+
i := strings.IndexByte(email, '@')
140+
local := strings.SplitN(email[:i], "+", 2)[0]
141+
local = strings.ReplaceAll(local, ".", "")
142+
domain := email[i:]
143+
s[local+domain] = true
144+
}
145+
return len(s)
146+
}
147+
```
148+
133149
### **...**
134150

135151
```

solution/0900-0999/0929.Unique Email Addresses/README_EN.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@
6464
```python
6565
class Solution:
6666
def numUniqueEmails(self, emails: List[str]) -> int:
67-
ans = 0
6867
s = set()
6968
for email in emails:
7069
local, domain = email.split('@')
7170
local = local.replace('.', '')
72-
if '+' in local:
73-
local = local[:local.find('+')]
71+
if (i := local.find('+')) != -1:
72+
local = local[:i]
7473
s.add(local + '@' + domain)
7574
return len(s)
7675
```
@@ -83,9 +82,8 @@ class Solution {
8382
Set<String> s = new HashSet<>();
8483
for (String email : emails) {
8584
String[] t = email.split("@");
86-
String local = t[0];
85+
String local = t[0].replace(".", "");
8786
String domain = t[1];
88-
local = local.replace(".", "");
8987
int i = local.indexOf('+');
9088
if (i != -1) {
9189
local = local.substring(0, i);
@@ -120,6 +118,22 @@ public:
120118
};
121119
```
122120
121+
### **Go**
122+
123+
```go
124+
func numUniqueEmails(emails []string) int {
125+
s := map[string]bool{}
126+
for _, email := range emails {
127+
i := strings.IndexByte(email, '@')
128+
local := strings.SplitN(email[:i], "+", 2)[0]
129+
local = strings.ReplaceAll(local, ".", "")
130+
domain := email[i:]
131+
s[local+domain] = true
132+
}
133+
return len(s)
134+
}
135+
```
136+
123137
### **...**
124138

125139
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
func numUniqueEmails(emails []string) int {
2+
s := map[string]bool{}
3+
for _, email := range emails {
4+
i := strings.IndexByte(email, '@')
5+
local := strings.SplitN(email[:i], "+", 2)[0]
6+
local = strings.ReplaceAll(local, ".", "")
7+
domain := email[i:]
8+
s[local+domain] = true
9+
}
10+
return len(s)
11+
}

solution/0900-0999/0929.Unique Email Addresses/Solution.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ public int numUniqueEmails(String[] emails) {
33
Set<String> s = new HashSet<>();
44
for (String email : emails) {
55
String[] t = email.split("@");
6-
String local = t[0];
6+
String local = t[0].replace(".", "");
77
String domain = t[1];
8-
local = local.replace(".", "");
98
int i = local.indexOf('+');
109
if (i != -1) {
1110
local = local.substring(0, i);
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
class Solution:
22
def numUniqueEmails(self, emails: List[str]) -> int:
3-
ans = 0
43
s = set()
54
for email in emails:
65
local, domain = email.split('@')
76
local = local.replace('.', '')
8-
if '+' in local:
9-
local = local[: local.find('+')]
7+
if (i := local.find('+')) != -1:
8+
local = local[:i]
109
s.add(local + '@' + domain)
1110
return len(s)

0 commit comments

Comments
 (0)