Skip to content

Commit ae3bb12

Browse files
committed
📝 docs : add 929. 独特的电子邮件地址.md
1 parent 7f5ff13 commit ae3bb12

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## 929. 独特的电子邮件地址
2+
> https://leetcode-cn.com/problems/unique-email-addresses/
3+
4+
5+
### Java
6+
```java
7+
/*
8+
* @Author: Goog Tech
9+
* @Date: 2020-08-29 23:17:50
10+
* @LastEditTime: 2020-08-29 23:18:19
11+
* @Description: https://leetcode-cn.com/problems/unique-email-addresses/
12+
* @FilePath: \leetcode-googtech\#929. Unique Email Addresses\Solution.java
13+
* @WebSite: https://algorithm.show/
14+
*/
15+
16+
class Solution {
17+
public int numUniqueEmails(String[] emails) {
18+
Set<String> set = new HashSet<>();
19+
for(String email : emails) {
20+
StringBuilder sb = new StringBuilder();
21+
// substring(int beginIndex, int endIndex)
22+
sb.append(email.substring(0, email.indexOf('+') == -1 ? email.indexOf('@') : email.indexOf('+')).replace(".", ""));
23+
// substring(int beginIndex)
24+
sb.append(email.substring(email.indexOf('@')));
25+
set.add(sb.toString());
26+
}
27+
return set.size();
28+
}
29+
}
30+
```
31+
32+
### Python
33+
```python
34+
'''
35+
Author: Goog Tech
36+
Date: 2020-08-29 23:17:56
37+
LastEditTime: 2020-08-29 23:18:12
38+
Description: https://leetcode-cn.com/problems/unique-email-addresses/
39+
FilePath: \leetcode-googtech\#929. Unique Email Addresses\Solution.py
40+
WebSite: https://algorithm.show/
41+
'''
42+
43+
class Solution(object):
44+
def numUniqueEmails(self, emails):
45+
"""
46+
:type emails: List[str]
47+
:rtype: int
48+
"""
49+
# 初始化用于存储邮件地址的 Set 集合
50+
emailSet = set()
51+
# 逐个遍历数组中的邮件地址
52+
for email in emails:
53+
# 分割邮件中的本地名称与域名
54+
name, domain = email.split('@')
55+
# 判断本地名称中是否存在符号 '+'
56+
if name.find('+') == -1:
57+
# 本地名称中不存在符号 '+',所以仅删除名称中的符号 '.' 即可
58+
name = name.replace('.','')
59+
else:
60+
# 忽略本地名称中符号 '+' 后面的字符,并删除名称中的符号 '.'
61+
name = name[:name.find('+')].replace('.', '')
62+
# 重新组合本地名称与域名,并将其存储到 Set 集合中
63+
emailSet.add(name + '@' + domain)
64+
# 返回 Set 集合中不同邮件的数量
65+
return len(emailSet)
66+
```

docs/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
* [876.链表的中间结点](LeetCode刷题之旅及题目解析/876.链表的中间结点/876.链表的中间结点.md)
113113
* [905.按奇偶排序数组](LeetCode刷题之旅及题目解析/905.按奇偶排序数组/905.按奇偶排序数组.md)
114114
* [917.仅仅反转字母](LeetCode刷题之旅及题目解析/917.仅仅反转字母/917.仅仅反转字母.md)
115+
* [929.独特的电子邮件地址](LeetCode刷题之旅及题目解析/929.独特的电子邮件地址/929.独特的电子邮件地址.md)
115116
* [938.二叉搜索树的范围和](LeetCode刷题之旅及题目解析/938.二叉搜索树的范围和/938.二叉搜索树的范围和.md)
116117
* [977.有序数组的平方](LeetCode刷题之旅及题目解析/977.有序数组的平方/977.有序数组的平方.md)
117118
* [1021.删除最外层的括号](LeetCode刷题之旅及题目解析/1021.删除最外层的括号/1021.删除最外层的括号.md)

0 commit comments

Comments
 (0)