-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueEmails.java
More file actions
41 lines (29 loc) · 1.11 KB
/
Copy pathUniqueEmails.java
File metadata and controls
41 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package LeetcodePractice;
import java.util.*;
public class UniqueEmails {
public static int numUniqueEmails(String[] emails) {
Set<String> unique = new HashSet<>();
for (String email : emails) {
String[] parts = email.split("@");
String local = parts[0];
String domain = parts[1];
int plusIndex = local.indexOf('+');
if (plusIndex != -1) {
local = local.substring(0, plusIndex);
}
local = local.replace(".", "");
unique.add(local + "@" + domain);
}
return unique.size();
}
public static void main(String[] args) {
String[] emails1 = {
"test.email+alex@leetcode.com",
"test.e.mail+bob.cathy@leetcode.com",
"testemail+david@lee.tcode.com"
};
System.out.println(numUniqueEmails(emails1));
String[] emails2 = {"a@leetcode.com","b@leetcode.com","c@leetcode.com"};
System.out.println(numUniqueEmails(emails2));
}
}